diff --git a/satellite/marketingweb/server.go b/satellite/marketingweb/server.go index db7bd86ee..cc028f721 100644 --- a/satellite/marketingweb/server.go +++ b/satellite/marketingweb/server.go @@ -115,6 +115,8 @@ func (s *Server) parseTemplates() (err error) { filepath.Join(s.templateDir, "partner-offers-modal.html"), filepath.Join(s.templateDir, "stop-free-credit.html"), filepath.Join(s.templateDir, "stop-referral-offer.html"), + filepath.Join(s.templateDir, "partner-offers.html"), + filepath.Join(s.templateDir, "stop-partner-offer.html"), ) pageNotFoundFiles := append(s.commonPages(), @@ -171,6 +173,9 @@ func (s *Server) CreateOffer(w http.ResponseWriter, req *http.Request) { offer.Type = rewards.Referral case "free-credit": offer.Type = rewards.FreeCredit + case "partner-offer": + offer.Type = rewards.Partner + offer.Name = offer.FormatPartnerName() default: err := errs.New("response status %d : invalid offer type", http.StatusBadRequest) s.serveBadRequest(w, req, err) diff --git a/satellite/marketingweb/server_test.go b/satellite/marketingweb/server_test.go index 22fb1b5dc..8b0d1c85f 100644 --- a/satellite/marketingweb/server_test.go +++ b/satellite/marketingweb/server_test.go @@ -42,7 +42,17 @@ func TestCreateAndStopOffers(t *testing.T) { }, { Path: "/create/free-credit-offer", Values: url.Values{ - "Name": {"Free Credit Credit"}, + "Name": {"Free Credit"}, + "Description": {"desc"}, + "ExpiresAt": {"2119-06-27"}, + "InviteeCredit": {"50"}, + "InviteeCreditDurationDays": {"50"}, + "RedeemableCap": {"150"}, + }, + }, { + Path: "/create/partner-offer", + Values: url.Values{ + "Name": {"OSPP003-FileZilla"}, "Description": {"desc"}, "ExpiresAt": {"2119-06-27"}, "InviteeCredit": {"50"}, diff --git a/satellite/rewards/partners.go b/satellite/rewards/partners.go new file mode 100644 index 000000000..211ed6151 --- /dev/null +++ b/satellite/rewards/partners.go @@ -0,0 +1,67 @@ +// Copyright (C) 2019 Storj Labs, Inc. +// See LICENSE for copying information. + +package rewards + +// PartnerInfo contains the name and ID of an Open Source Partner +type PartnerInfo struct { + ID, Name string +} + +// FormattedName returns formatted partner name +func (p PartnerInfo) FormattedName() string { + return p.ID + "-" + p.Name +} + +// Partners contains a list of partners. +type Partners map[string]PartnerInfo + +// LoadPartnerInfos returns our current Open Source Partners. +func LoadPartnerInfos() Partners { + return Partners{ + "Couchbase": PartnerInfo{ + Name: "Couchbase", + ID: "OSPP001", + }, + "MongoDB": PartnerInfo{ + Name: "MongoDB", + ID: "OSPP002", + }, + "FileZilla": PartnerInfo{ + Name: "FileZilla", + ID: "OSPP003", + }, + "InfluxDB": PartnerInfo{ + Name: "InfluxDB", + ID: "OSPP004", + }, + "Kafka": PartnerInfo{ + Name: "Kafka", + ID: "OSPP005", + }, + "Minio": PartnerInfo{ + Name: "Minio", + ID: "OSPP006", + }, + "Nextcloud": PartnerInfo{ + Name: "Nextcloud", + ID: "OSPP007", + }, + "MariaDB": PartnerInfo{ + Name: "MariaDB", + ID: "OSPP008", + }, + "Plesk": PartnerInfo{ + Name: "Plesk", + ID: "OSPP009", + }, + "Pydio": PartnerInfo{ + Name: "Pydio", + ID: "OSPP010", + }, + "Zenko": PartnerInfo{ + Name: "Zenko", + ID: "OSPP011", + }, + } +} diff --git a/satellite/rewards/rewards.go b/satellite/rewards/rewards.go index 156ef6ba5..05a4939be 100644 --- a/satellite/rewards/rewards.go +++ b/satellite/rewards/rewards.go @@ -40,6 +40,19 @@ type NewOffer struct { Type OfferType } +// FormatPartnerName formats partner's name into combination of its partnerID and name +func (o NewOffer) FormatPartnerName() string { + if o.Type != Partner { + return o.Name + } + + partnerInfo := PartnerInfo{ + ID: LoadPartnerInfos()[o.Name].ID, + Name: o.Name, + } + return partnerInfo.FormattedName() +} + // UpdateOffer holds fields needed for update an offer type UpdateOffer struct { ID int @@ -112,10 +125,20 @@ type OrganizedOffers struct { Done Offers } +// OpenSourcePartner contains all data for an Open Source Partner. +type OpenSourcePartner struct { + PartnerInfo + PartnerOffers OrganizedOffers +} + +// PartnerSet contains a list of Open Source Partners. +type PartnerSet []OpenSourcePartner + // OfferSet provides a separation of marketing offers by type. type OfferSet struct { ReferralOffers OrganizedOffers FreeCredits OrganizedOffers + PartnerTables PartnerSet } // OrganizeOffersByStatus organizes offers by OfferStatus. @@ -138,8 +161,8 @@ func (offers Offers) OrganizeOffersByStatus() OrganizedOffers { // OrganizeOffersByType organizes offers by OfferType. func (offers Offers) OrganizeOffersByType() OfferSet { var ( - fc, ro Offers - offerSet OfferSet + fc, ro, p Offers + offerSet OfferSet ) for _, offer := range offers { @@ -148,6 +171,8 @@ func (offers Offers) OrganizeOffersByType() OfferSet { fc = append(fc, offer) case Referral: ro = append(ro, offer) + case Partner: + p = append(p, offer) default: continue } @@ -155,5 +180,46 @@ func (offers Offers) OrganizeOffersByType() OfferSet { offerSet.FreeCredits = fc.OrganizeOffersByStatus() offerSet.ReferralOffers = ro.OrganizeOffersByStatus() + offerSet.PartnerTables = organizePartnerData(p) return offerSet } + +// createPartnerSet generates a PartnerSet from the config file. +func createPartnerSet() PartnerSet { + partners := LoadPartnerInfos() + var ps PartnerSet + for _, partner := range partners { + ps = append(ps, OpenSourcePartner{ + PartnerInfo: PartnerInfo{ + Name: partner.Name, + ID: partner.ID, + }, + }) + } + return ps +} + +// matchOffersToPartnerSet assigns offers to the partner they belong to. +func matchOffersToPartnerSet(offers Offers, partnerSet PartnerSet) PartnerSet { + for i := range partnerSet { + var partnerOffersByName Offers + + for _, o := range offers { + if o.Name == partnerSet[i].PartnerInfo.FormattedName() { + partnerOffersByName = append(partnerOffersByName, o) + } + } + + partnerSet[i].PartnerOffers = partnerOffersByName.OrganizeOffersByStatus() + } + + return partnerSet +} + +// organizePartnerData returns a list of Open Source Partners +// whose offers have been organized by status, type, and +// assigned to the correct partner. +func organizePartnerData(offers Offers) PartnerSet { + partnerData := matchOffersToPartnerSet(offers, createPartnerSet()) + return partnerData +} diff --git a/satellite/rewards/rewards_test.go b/satellite/rewards/rewards_test.go index 3739f064c..baaf8ce1f 100644 --- a/satellite/rewards/rewards_test.go +++ b/satellite/rewards/rewards_test.go @@ -45,6 +45,18 @@ func TestOffer_Database(t *testing.T) { Status: rewards.Active, Type: rewards.FreeCredit, }, + { + Name: "partner", + Description: "test offer 2", + AwardCredit: currency.Cents(0), + InviteeCredit: currency.Cents(50), + AwardCreditDurationDays: 0, + InviteeCreditDurationDays: 30, + RedeemableCap: 50, + ExpiresAt: time.Now().UTC().Add(time.Hour * 1), + Status: rewards.Active, + Type: rewards.Partner, + }, } for i := range validOffers { diff --git a/satellite/satellitedb/dbx/satellitedb.dbx.go b/satellite/satellitedb/dbx/satellitedb.dbx.go index c27b350f5..a47a3052e 100644 --- a/satellite/satellitedb/dbx/satellitedb.dbx.go +++ b/satellite/satellitedb/dbx/satellitedb.dbx.go @@ -18,8 +18,9 @@ import ( "github.com/lib/pq" - "github.com/mattn/go-sqlite3" "math/rand" + + "github.com/mattn/go-sqlite3" ) // Prevent conditional imports from causing build failures diff --git a/web/marketing/css/style.css b/web/marketing/css/style.css index e20eb06a6..b10d4709a 100644 --- a/web/marketing/css/style.css +++ b/web/marketing/css/style.css @@ -192,21 +192,4 @@ input{ .header-row .col-heading{ margin-left:-110px; -} - -.partner-wrapper, -.partners-table{ - margin-left:-10px; - margin-right:0px; - padding-right:0px; -} - -.partners-table{ - width:1800px; -} - -.partner-wrapper{ - padding-left:0px; - overflow-x: auto; - max-width: 1150px; } \ No newline at end of file diff --git a/web/marketing/pages/free-offers.html b/web/marketing/pages/free-offers.html index b62bdd88e..33bbee36e 100644 --- a/web/marketing/pages/free-offers.html +++ b/web/marketing/pages/free-offers.html @@ -45,7 +45,7 @@ See LICENSE for copying information. --> {{end}} {{template "stopFreeCredit" .}}
-

Other Offers

+

Discontinued Offers

{{range .FreeCredits.Done}}
diff --git a/web/marketing/pages/home.html b/web/marketing/pages/home.html index ca4f8f87a..57dc1470b 100644 --- a/web/marketing/pages/home.html +++ b/web/marketing/pages/home.html @@ -15,11 +15,9 @@ See LICENSE for copying information. -->
{{template "freeOffers" .}} {{template "freeOffersModal" .}} - - {{template "partnerOffers" .}} - {{template "partnerOffersModal" .}} + + {{range .PartnerTables}} + {{template "partnerOffers" .}} + {{end}} {{end}} \ No newline at end of file diff --git a/web/marketing/pages/partner-offers-modal.html b/web/marketing/pages/partner-offers-modal.html index 44ead30ab..31a9867c2 100644 --- a/web/marketing/pages/partner-offers-modal.html +++ b/web/marketing/pages/partner-offers-modal.html @@ -2,7 +2,7 @@ See LICENSE for copying information. --> {{define "partnerOffersModal"}} -