From 0aca91a7935bf60cd657fb8cada8cc1f9b9331bc Mon Sep 17 00:00:00 2001 From: Lucas Menendez Date: Wed, 2 Oct 2024 13:39:32 +0200 Subject: [PATCH] remove organization data that is also provided by the sdk and vochain --- api/organizations.go | 23 ----------------- api/types.go | 54 ++++++++++++++++------------------------ db/helpers.go | 8 ------ db/organizations_test.go | 27 +------------------- db/types.go | 5 ---- 5 files changed, 23 insertions(+), 94 deletions(-) diff --git a/api/organizations.go b/api/organizations.go index bdf252e..2deacf1 100644 --- a/api/organizations.go +++ b/api/organizations.go @@ -66,15 +66,12 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request) // create the organization if err := a.db.SetOrganization(&db.Organization{ Address: signer.AddressString(), - Name: orgInfo.Name, Creator: user.Email, CreatedAt: time.Now(), Nonce: nonce, Type: db.OrganizationType(orgInfo.Type), - Description: orgInfo.Description, Size: orgInfo.Size, Color: orgInfo.Color, - Logo: orgInfo.Logo, Subdomain: orgInfo.Subdomain, Timezone: orgInfo.Timezone, Active: true, @@ -177,14 +174,6 @@ func (a *API) updateOrganizationHandler(w http.ResponseWriter, r *http.Request) } // update just the fields that can be updated and are not empty updateOrg := false - if newOrgInfo.Name != "" { - org.Name = newOrgInfo.Name - updateOrg = true - } - if newOrgInfo.Description != "" { - org.Description = newOrgInfo.Description - updateOrg = true - } if newOrgInfo.Website != "" { org.Website = newOrgInfo.Website updateOrg = true @@ -197,14 +186,6 @@ func (a *API) updateOrganizationHandler(w http.ResponseWriter, r *http.Request) org.Color = newOrgInfo.Color updateOrg = true } - if newOrgInfo.Logo != "" { - org.Logo = newOrgInfo.Logo - updateOrg = true - } - if newOrgInfo.Header != "" { - org.Header = newOrgInfo.Header - updateOrg = true - } if newOrgInfo.Subdomain != "" { org.Subdomain = newOrgInfo.Subdomain updateOrg = true @@ -217,10 +198,6 @@ func (a *API) updateOrganizationHandler(w http.ResponseWriter, r *http.Request) org.Timezone = newOrgInfo.Timezone updateOrg = true } - if newOrgInfo.Language != "" { - org.Language = newOrgInfo.Language - updateOrg = true - } if newOrgInfo.Active != org.Active { org.Active = newOrgInfo.Active updateOrg = true diff --git a/api/types.go b/api/types.go index 05f01f6..a345a69 100644 --- a/api/types.go +++ b/api/types.go @@ -9,22 +9,17 @@ import ( // Organization is the struct that represents an organization in the API type OrganizationInfo struct { - Address string `json:"address"` - Name string `json:"name"` - Website string `json:"website"` - CreatedAt string `json:"createdAt"` - Type string `json:"type"` - Description string `json:"description"` - Size string `json:"size"` - Color string `json:"color"` - Logo string `json:"logo"` - Header string `json:"header"` - Subdomain string `json:"subdomain"` - Country string `json:"country"` - Timezone string `json:"timezone"` - Language string `json:"language"` - Active bool `json:"active"` - Parent *OrganizationInfo `json:"parent"` + Address string `json:"address"` + Website string `json:"website"` + CreatedAt string `json:"createdAt"` + Type string `json:"type"` + Size string `json:"size"` + Color string `json:"color"` + Subdomain string `json:"subdomain"` + Country string `json:"country"` + Timezone string `json:"timezone"` + Active bool `json:"active"` + Parent *OrganizationInfo `json:"parent"` } // OrganizationMembers is the struct that represents a list of members of @@ -117,21 +112,16 @@ func organizationFromDB(dbOrg, parent *db.Organization) *OrganizationInfo { parentOrg = organizationFromDB(parent, nil) } return &OrganizationInfo{ - Address: dbOrg.Address, - Name: dbOrg.Name, - Website: dbOrg.Website, - CreatedAt: dbOrg.CreatedAt.Format(time.RFC3339), - Type: string(dbOrg.Type), - Description: dbOrg.Description, - Size: dbOrg.Size, - Color: dbOrg.Color, - Logo: dbOrg.Logo, - Header: dbOrg.Header, - Subdomain: dbOrg.Subdomain, - Country: dbOrg.Country, - Timezone: dbOrg.Timezone, - Language: dbOrg.Language, - Active: dbOrg.Active, - Parent: parentOrg, + Address: dbOrg.Address, + Website: dbOrg.Website, + CreatedAt: dbOrg.CreatedAt.Format(time.RFC3339), + Type: string(dbOrg.Type), + Size: dbOrg.Size, + Color: dbOrg.Color, + Subdomain: dbOrg.Subdomain, + Country: dbOrg.Country, + Timezone: dbOrg.Timezone, + Active: dbOrg.Active, + Parent: parentOrg, } } diff --git a/db/helpers.go b/db/helpers.go index 031030c..730c1d5 100644 --- a/db/helpers.go +++ b/db/helpers.go @@ -121,14 +121,6 @@ func (ms *MongoStorage) createIndexes() error { if _, err := ms.users.Indexes().CreateOne(ctx, userPhoneIndex); err != nil { return fmt.Errorf("failed to create index on phone for users: %w", err) } - // create an index for the 'name' field on organizations (must be unique) - organizationNameIndex := mongo.IndexModel{ - Keys: bson.D{{Key: "name", Value: 1}}, // 1 for ascending order - Options: options.Index().SetUnique(true), - } - if _, err := ms.organizations.Indexes().CreateOne(ctx, organizationNameIndex); err != nil { - return fmt.Errorf("failed to create index on name for organizations: %w", err) - } // create an index for the ('code', 'type') tuple on user verifications (must be unique) verificationCodeIndex := mongo.IndexModel{ Keys: bson.D{ diff --git a/db/organizations_test.go b/db/organizations_test.go index cc4f761..1d0aa11 100644 --- a/db/organizations_test.go +++ b/db/organizations_test.go @@ -22,7 +22,6 @@ func TestOrganization(t *testing.T) { parentAddress := "parentOrgToGet" c.Assert(db.SetOrganization(&Organization{ Address: address, - Name: "Child Organization", Parent: parentAddress, }), qt.IsNil) // test not found parent organization @@ -32,7 +31,6 @@ func TestOrganization(t *testing.T) { // create a new parent organization c.Assert(db.SetOrganization(&Organization{ Address: parentAddress, - Name: "Parent Organization", }), qt.IsNil) // test found organization and parent organization org, parentOrg, err = db.Organization(address, true) @@ -52,38 +50,25 @@ func TestSetOrganization(t *testing.T) { c := qt.New(t) // create a new organization address := "orgToSet" - orgName := "Organization" c.Assert(db.SetOrganization(&Organization{ Address: address, - Name: orgName, }), qt.IsNil) org, _, err := db.Organization(address, false) c.Assert(err, qt.IsNil) c.Assert(org, qt.Not(qt.IsNil)) c.Assert(org.Address, qt.Equals, address) - c.Assert(org.Name, qt.Equals, orgName) // update the organization - orgName = "New Organization" c.Assert(db.SetOrganization(&Organization{ Address: address, - Name: orgName, }), qt.IsNil) org, _, err = db.Organization(address, false) c.Assert(err, qt.IsNil) c.Assert(org, qt.Not(qt.IsNil)) c.Assert(org.Address, qt.Equals, address) - c.Assert(org.Name, qt.Equals, orgName) - // try to create a new organization with the same name - newOrgAddress := "newOrgToSet" - c.Assert(db.SetOrganization(&Organization{ - Address: newOrgAddress, - Name: orgName, - }), qt.IsNotNil) // try to create a new organization with a not found creator - newOrgName := "New Organization 2" + newOrgAddress := "newOrgToSet" c.Assert(db.SetOrganization(&Organization{ Address: newOrgAddress, - Name: newOrgName, Creator: testUserEmail, }), qt.IsNotNil) // register the creator and retry to create the organization @@ -94,7 +79,6 @@ func TestSetOrganization(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(db.SetOrganization(&Organization{ Address: newOrgAddress, - Name: newOrgName, Creator: testUserEmail, }), qt.IsNil) } @@ -108,16 +92,13 @@ func TestDeleteOrganization(t *testing.T) { c := qt.New(t) // create a new organization and delete it address := "orgToDelete" - name := "Organization to delete" c.Assert(db.SetOrganization(&Organization{ Address: address, - Name: name, }), qt.IsNil) org, _, err := db.Organization(address, false) c.Assert(err, qt.IsNil) c.Assert(org, qt.Not(qt.IsNil)) c.Assert(org.Address, qt.Equals, address) - c.Assert(org.Name, qt.Equals, name) // delete the organization c.Assert(db.DelOrganization(org), qt.IsNil) // check the organization doesn't exist @@ -135,7 +116,6 @@ func TestReplaceCreatorEmail(t *testing.T) { c := qt.New(t) // create a new organization with a creator address := "orgToReplaceCreator" - name := "Organization to replace creator" _, err := db.SetUser(&User{ Email: testUserEmail, Password: testUserPass, @@ -143,14 +123,12 @@ func TestReplaceCreatorEmail(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(db.SetOrganization(&Organization{ Address: address, - Name: name, Creator: testUserEmail, }), qt.IsNil) org, _, err := db.Organization(address, false) c.Assert(err, qt.IsNil) c.Assert(org, qt.Not(qt.IsNil)) c.Assert(org.Address, qt.Equals, address) - c.Assert(org.Name, qt.Equals, name) c.Assert(org.Creator, qt.Equals, testUserEmail) // replace the creator email newCreator := "mySecond@email.test" @@ -159,7 +137,6 @@ func TestReplaceCreatorEmail(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(org, qt.Not(qt.IsNil)) c.Assert(org.Address, qt.Equals, address) - c.Assert(org.Name, qt.Equals, name) c.Assert(org.Creator, qt.Equals, newCreator) } @@ -172,7 +149,6 @@ func TestOrganizationsMembers(t *testing.T) { c := qt.New(t) // create a new organization with a creator address := "orgToReplaceCreator" - name := "Organization to replace creator" _, err := db.SetUser(&User{ Email: testUserEmail, Password: testUserPass, @@ -180,7 +156,6 @@ func TestOrganizationsMembers(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(db.SetOrganization(&Organization{ Address: address, - Name: name, Creator: testUserEmail, }), qt.IsNil) _, _, err = db.Organization(address, false) diff --git a/db/types.go b/db/types.go index 3ab1df2..d86e2bf 100644 --- a/db/types.go +++ b/db/types.go @@ -42,21 +42,16 @@ type OrganizationMember struct { type Organization struct { Address string `json:"address" bson:"_id"` - Name string `json:"name" bson:"name"` Website string `json:"website" bson:"website"` Type OrganizationType `json:"type" bson:"type"` Creator string `json:"creator" bson:"creator"` CreatedAt time.Time `json:"createdAt" bson:"createdAt"` Nonce string `json:"nonce" bson:"nonce"` - Description string `json:"description" bson:"description"` Size string `json:"size" bson:"size"` Color string `json:"color" bson:"color"` - Logo string `json:"logo" bson:"logo"` - Header string `json:"header" bson:"header"` Subdomain string `json:"subdomain" bson:"subdomain"` Country string `json:"country" bson:"country"` Timezone string `json:"timezone" bson:"timezone"` - Language string `json:"language" bson:"language"` Active bool `json:"active" bson:"active"` TokensPurchased uint64 `json:"tokensPurchased" bson:"tokensPurchased"` TokensRemaining uint64 `json:"tokensRemaining" bson:"tokensRemaining"`