From acd70a25f5ef9a79bfbd5dbd450612e7e6bef731 Mon Sep 17 00:00:00 2001 From: MuhammadUmer44 Date: Tue, 2 Jul 2024 03:32:31 +0500 Subject: [PATCH 1/5] write unit test GetUserDropdownWorkspaces --- db/db.go | 10 +++++ handlers/workspaces.go | 50 +++++++++++----------- handlers/workspaces_test.go | 84 +++++++++++++++++++++++++++++++++++++ routes/workspaces.go | 4 +- 4 files changed, 121 insertions(+), 27 deletions(-) diff --git a/db/db.go b/db/db.go index 5797971fd..53bc968eb 100644 --- a/db/db.go +++ b/db/db.go @@ -1394,6 +1394,16 @@ func (db database) GetPerson(id uint) Person { return m } +func (db database) DeleteWorkSpaceAllData() error { + tables := []string{"workspace_user_roles", "workspaces"} + for _, table := range tables { + if err := db.db.Exec("DELETE FROM " + table).Error; err != nil { + return err + } + } + return nil +} + func (db database) GetPersonByPubkey(pubkey string) Person { m := Person{} db.db.Where("owner_pub_key = ? AND (deleted = false OR deleted is null)", pubkey).Find(&m) diff --git a/handlers/workspaces.go b/handlers/workspaces.go index 7069e56c1..0d45e0306 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -454,7 +454,7 @@ func GetUserRoles(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(userRoles) } -func GetUserWorkspaces(w http.ResponseWriter, r *http.Request) { +func (oh *workspaceHandler) GetUserWorkspaces(w http.ResponseWriter, r *http.Request) { userIdParam := chi.URLParam(r, "userId") userId, _ := utils.ConvertStringToUint(userIdParam) @@ -464,9 +464,9 @@ func GetUserWorkspaces(w http.ResponseWriter, r *http.Request) { return } - user := db.DB.GetPerson(userId) + user := oh.db.GetPerson(userId) // get the user workspaces - workspaces := GetAllUserWorkspaces(user.OwnerPubKey) + workspaces := oh.GetAllUserWorkspaces(user.OwnerPubKey) w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(workspaces) @@ -482,23 +482,23 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * return } - user := db.DB.GetPerson(userId) + user := oh.db.GetPerson(userId) // get the workspaces created by the user, then get all the workspaces // the user has been added to, loop through to get the workspace - workspaces := GetCreatedWorkspaces(user.OwnerPubKey) - assignedWorkspaces := db.DB.GetUserAssignedWorkspaces(user.OwnerPubKey) + workspaces := oh.GetCreatedWorkspaces(user.OwnerPubKey) + assignedWorkspaces := oh.db.GetUserAssignedWorkspaces(user.OwnerPubKey) for _, value := range assignedWorkspaces { uuid := value.WorkspaceUuid - workspace := db.DB.GetWorkspaceByUuid(uuid) - bountyCount := db.DB.GetWorkspaceBountyCount(uuid) - hasRole := db.UserHasAccess(user.OwnerPubKey, uuid, db.ViewReport) + workspace := oh.db.GetWorkspaceByUuid(uuid) + bountyCount := oh.db.GetWorkspaceBountyCount(uuid) + hasRole := oh.userHasAccess(user.OwnerPubKey, uuid, db.ViewReport) hasBountyRoles := oh.userHasManageBountyRoles(user.OwnerPubKey, uuid) // don't add deleted workspaces to the list if !workspace.Deleted && hasBountyRoles { if hasRole { - budget := db.DB.GetWorkspaceBudget(uuid) + budget := oh.db.GetWorkspaceBudget(uuid) workspace.Budget = budget.TotalBudget } else { workspace.Budget = 0 @@ -512,16 +512,16 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * json.NewEncoder(w).Encode(workspaces) } -func GetCreatedWorkspaces(pubkey string) []db.Workspace { - workspaces := db.DB.GetUserCreatedWorkspaces(pubkey) +func (oh *workspaceHandler) GetCreatedWorkspaces(pubkey string) []db.Workspace { + workspaces := oh.db.GetUserCreatedWorkspaces(pubkey) // add bounty count to the workspace for index, value := range workspaces { uuid := value.Uuid - bountyCount := db.DB.GetWorkspaceBountyCount(uuid) - hasRole := db.UserHasAccess(pubkey, uuid, db.ViewReport) + bountyCount := oh.db.GetWorkspaceBountyCount(uuid) + hasRole := oh.userHasAccess(pubkey, uuid, db.ViewReport) if hasRole { - budget := db.DB.GetWorkspaceBudget(uuid) + budget := oh.db.GetWorkspaceBudget(uuid) workspaces[index].Budget = budget.TotalBudget } else { workspaces[index].Budget = 0 @@ -687,7 +687,7 @@ func (oh *workspaceHandler) PollUserWorkspacesBudget(w http.ResponseWriter, r *h } // get the user workspaces - workspaces := GetAllUserWorkspaces(pubKeyFromAuth) + workspaces := oh.GetAllUserWorkspaces(pubKeyFromAuth) // loop through the worksppaces and get each workspace invoice for _, space := range workspaces { // get all workspace invoice @@ -737,7 +737,7 @@ func GetInvoicesCount(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(invoiceCount) } -func GetAllUserInvoicesCount(w http.ResponseWriter, r *http.Request) { +func (oh *workspaceHandler) GetAllUserInvoicesCount(w http.ResponseWriter, r *http.Request) { ctx := r.Context() pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string) @@ -748,9 +748,9 @@ func GetAllUserInvoicesCount(w http.ResponseWriter, r *http.Request) { } allCount := int64(0) - workspaces := GetAllUserWorkspaces(pubKeyFromAuth) + workspaces := oh.GetAllUserWorkspaces(pubKeyFromAuth) for _, space := range workspaces { - invoiceCount := db.DB.GetWorkspaceInvoicesCount(space.Uuid) + invoiceCount := oh.db.GetWorkspaceInvoicesCount(space.Uuid) allCount += invoiceCount } w.WriteHeader(http.StatusOK) @@ -995,20 +995,20 @@ func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r json.NewEncoder(w).Encode(workspaceFeatures) } -func GetAllUserWorkspaces(pubkey string) []db.Workspace { +func (oh *workspaceHandler) GetAllUserWorkspaces(pubkey string) []db.Workspace { // get the workspaces created by the user, then get all the workspaces // the user has been added to, loop through to get the workspace - workspaces := GetCreatedWorkspaces(pubkey) - assignedWorkspaces := db.DB.GetUserAssignedWorkspaces(pubkey) + workspaces := oh.GetCreatedWorkspaces(pubkey) + assignedWorkspaces := oh.db.GetUserAssignedWorkspaces(pubkey) for _, value := range assignedWorkspaces { uuid := value.WorkspaceUuid - workspace := db.DB.GetWorkspaceByUuid(uuid) - bountyCount := db.DB.GetWorkspaceBountyCount(uuid) + workspace := oh.db.GetWorkspaceByUuid(uuid) + bountyCount := oh.db.GetWorkspaceBountyCount(uuid) hasRole := db.UserHasAccess(pubkey, uuid, db.ViewReport) // don't add deleted workspaces to the list if !workspace.Deleted { if hasRole { - budget := db.DB.GetWorkspaceBudget(uuid) + budget := oh.db.GetWorkspaceBudget(uuid) workspace.Budget = budget.TotalBudget } else { workspace.Budget = 0 diff --git a/handlers/workspaces_test.go b/handlers/workspaces_test.go index cfaa6448d..259f6a677 100644 --- a/handlers/workspaces_test.go +++ b/handlers/workspaces_test.go @@ -8,6 +8,7 @@ import ( "math/rand" "net/http" "net/http/httptest" + "strconv" "strings" "testing" "time" @@ -930,7 +931,90 @@ func TestGetWorkspaceUsers(t *testing.T) { } func TestGetUserDropdownWorkspaces(t *testing.T) { + teardownSuite := SetupSuite(t) + defer teardownSuite(t) + + db.TestDB.DeleteWorkSpaceAllData() + + oHandler := NewWorkspaceHandler(db.TestDB) + + person := db.Person{ + Uuid: uuid.New().String(), + OwnerAlias: "test-alias", + UniqueName: "test-unique-name", + OwnerPubKey: "test-pubkey", + PriceToMeet: 0, + Description: "test-description", + } + person2 := db.Person{ + Uuid: uuid.New().String(), + OwnerAlias: "test-alias2", + UniqueName: "test-unique-name2", + OwnerPubKey: "test-pubkey2", + PriceToMeet: 0, + Description: "test-description2", + } + db.TestDB.CreateOrEditPerson(person) + db.TestDB.CreateOrEditPerson(person2) + + workspace := db.Workspace{ + Uuid: uuid.New().String(), + Name: "test-workspace" + uuid.New().String(), + OwnerPubKey: person2.OwnerPubKey, + Github: "https://github.com/test", + Website: "https://www.testwebsite.com", + Description: "test-description", + } + db.TestDB.CreateOrEditWorkspace(workspace) + workspace = db.TestDB.GetWorkspaceByUuid(workspace.Uuid) + ctx := context.WithValue(context.Background(), auth.ContextKey, workspace.OwnerPubKey) + + roles := []db.WorkspaceUserRoles{ + {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "ADD BOUNTY"}, + {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "UPDATE BOUNTY"}, + {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "DELETE BOUNTY"}, + {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "PAY BOUNTY"}, + } + db.TestDB.CreateUserRoles(roles, workspace.Uuid, person2.OwnerPubKey) + + dbPerson := db.TestDB.GetPersonByUuid(person2.Uuid) + + handlerUserHasAccess := func(pubKeyFromAuth string, uuid string, role string) bool { + return true + } + oHandler.userHasAccess = handlerUserHasAccess + + handlerUserHasManageBountyRoles := func(pubKeyFromAuth string, uuid string) bool { + return true + } + oHandler.userHasManageBountyRoles = handlerUserHasManageBountyRoles + + rr := httptest.NewRecorder() + rctx := chi.NewRouteContext() + rctx.URLParams.Add("userId", strconv.Itoa(int(dbPerson.ID))) + req, err := http.NewRequestWithContext(context.WithValue(ctx, chi.RouteCtxKey, rctx), http.MethodGet, "/user/dropdown/"+strconv.Itoa(int(dbPerson.ID)), nil) + if err != nil { + t.Fatal(err) + } + + handler := http.HandlerFunc(oHandler.GetUserDropdownWorkspaces) + handler.ServeHTTP(rr, req) + + assert.Equal(t, http.StatusOK, rr.Code) + + var responseWorkspaces []db.Workspace + err = json.Unmarshal(rr.Body.Bytes(), &responseWorkspaces) + if err != nil { + t.Fatal(err) + } + assert.NotEmpty(t, responseWorkspaces) + assert.Equal(t, workspace.Uuid, responseWorkspaces[0].Uuid) + assert.Equal(t, workspace.Name, responseWorkspaces[0].Name) + assert.Equal(t, workspace.OwnerPubKey, responseWorkspaces[0].OwnerPubKey) + assert.Equal(t, workspace.Github, responseWorkspaces[0].Github) + assert.Equal(t, workspace.Website, responseWorkspaces[0].Website) + assert.Equal(t, workspace.Description, responseWorkspaces[0].Description) } func TestCreateOrEditWorkspaceRepository(t *testing.T) { diff --git a/routes/workspaces.go b/routes/workspaces.go index 8a6753c60..27ec8a8b9 100644 --- a/routes/workspaces.go +++ b/routes/workspaces.go @@ -18,7 +18,7 @@ func WorkspaceRoutes() chi.Router { r.Get("/users/{uuid}/count", handlers.GetWorkspaceUsersCount) r.Get("/bounties/{uuid}", workspaceHandlers.GetWorkspaceBounties) r.Get("/bounties/{uuid}/count", workspaceHandlers.GetWorkspaceBountiesCount) - r.Get("/user/{userId}", handlers.GetUserWorkspaces) + r.Get("/user/{userId}", workspaceHandlers.GetUserWorkspaces) r.Get("/user/dropdown/{userId}", workspaceHandlers.GetUserDropdownWorkspaces) }) r.Group(func(r chi.Router) { @@ -38,7 +38,7 @@ func WorkspaceRoutes() chi.Router { r.Get("/poll/invoices/{uuid}", workspaceHandlers.PollBudgetInvoices) r.Get("/poll/user/invoices", workspaceHandlers.PollUserWorkspacesBudget) r.Get("/invoices/count/{uuid}", handlers.GetInvoicesCount) - r.Get("/user/invoices/count", handlers.GetAllUserInvoicesCount) + r.Get("/user/invoices/count", workspaceHandlers.GetAllUserInvoicesCount) r.Delete("/delete/{uuid}", workspaceHandlers.DeleteWorkspace) r.Post("/mission", workspaceHandlers.UpdateWorkspace) From 0c096ca278516851c13baa5372e22c1f507799b6 Mon Sep 17 00:00:00 2001 From: MuhammadUmer44 Date: Wed, 3 Jul 2024 14:59:29 +0500 Subject: [PATCH 2/5] Address write unit test GetUserDropdownWorkspaces --- db/db.go | 4 +++ handlers/workspaces_test.go | 57 ++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/db/db.go b/db/db.go index 53bc968eb..b95fd5552 100644 --- a/db/db.go +++ b/db/db.go @@ -1404,6 +1404,10 @@ func (db database) DeleteWorkSpaceAllData() error { return nil } +func (db database) DeleteWorkSpaceUserAccessData(pubKeyFromAuth string, uuid string, role string) bool { + return true +} + func (db database) GetPersonByPubkey(pubkey string) Person { m := Person{} db.db.Where("owner_pub_key = ? AND (deleted = false OR deleted is null)", pubkey).Find(&m) diff --git a/handlers/workspaces_test.go b/handlers/workspaces_test.go index 92bd6b1ac..7bcc42171 100644 --- a/handlers/workspaces_test.go +++ b/handlers/workspaces_test.go @@ -1207,6 +1207,7 @@ func TestGetUserDropdownWorkspaces(t *testing.T) { db.TestDB.DeleteWorkSpaceAllData() oHandler := NewWorkspaceHandler(db.TestDB) + oHandler.userHasAccess = db.TestDB.DeleteWorkSpaceUserAccessData person := db.Person{ Uuid: uuid.New().String(), @@ -1249,42 +1250,34 @@ func TestGetUserDropdownWorkspaces(t *testing.T) { dbPerson := db.TestDB.GetPersonByUuid(person2.Uuid) - handlerUserHasAccess := func(pubKeyFromAuth string, uuid string, role string) bool { - return true - } - oHandler.userHasAccess = handlerUserHasAccess - - handlerUserHasManageBountyRoles := func(pubKeyFromAuth string, uuid string) bool { - return true - } - oHandler.userHasManageBountyRoles = handlerUserHasManageBountyRoles - - rr := httptest.NewRecorder() - rctx := chi.NewRouteContext() - rctx.URLParams.Add("userId", strconv.Itoa(int(dbPerson.ID))) - req, err := http.NewRequestWithContext(context.WithValue(ctx, chi.RouteCtxKey, rctx), http.MethodGet, "/user/dropdown/"+strconv.Itoa(int(dbPerson.ID)), nil) - if err != nil { - t.Fatal(err) - } + t.Run("should return user dropdown workspaces", func(t *testing.T) { + rr := httptest.NewRecorder() + rctx := chi.NewRouteContext() + rctx.URLParams.Add("userId", strconv.Itoa(int(dbPerson.ID))) + req, err := http.NewRequestWithContext(context.WithValue(ctx, chi.RouteCtxKey, rctx), http.MethodGet, "/user/dropdown/"+strconv.Itoa(int(dbPerson.ID)), nil) + if err != nil { + t.Fatal(err) + } - handler := http.HandlerFunc(oHandler.GetUserDropdownWorkspaces) - handler.ServeHTTP(rr, req) + handler := http.HandlerFunc(oHandler.GetUserDropdownWorkspaces) + handler.ServeHTTP(rr, req) - assert.Equal(t, http.StatusOK, rr.Code) + assert.Equal(t, http.StatusOK, rr.Code) - var responseWorkspaces []db.Workspace - err = json.Unmarshal(rr.Body.Bytes(), &responseWorkspaces) - if err != nil { - t.Fatal(err) - } + var responseWorkspaces []db.Workspace + err = json.Unmarshal(rr.Body.Bytes(), &responseWorkspaces) + if err != nil { + t.Fatal(err) + } - assert.NotEmpty(t, responseWorkspaces) - assert.Equal(t, workspace.Uuid, responseWorkspaces[0].Uuid) - assert.Equal(t, workspace.Name, responseWorkspaces[0].Name) - assert.Equal(t, workspace.OwnerPubKey, responseWorkspaces[0].OwnerPubKey) - assert.Equal(t, workspace.Github, responseWorkspaces[0].Github) - assert.Equal(t, workspace.Website, responseWorkspaces[0].Website) - assert.Equal(t, workspace.Description, responseWorkspaces[0].Description) + assert.NotEmpty(t, responseWorkspaces) + assert.Equal(t, workspace.Uuid, responseWorkspaces[0].Uuid) + assert.Equal(t, workspace.Name, responseWorkspaces[0].Name) + assert.Equal(t, workspace.OwnerPubKey, responseWorkspaces[0].OwnerPubKey) + assert.Equal(t, workspace.Github, responseWorkspaces[0].Github) + assert.Equal(t, workspace.Website, responseWorkspaces[0].Website) + assert.Equal(t, workspace.Description, responseWorkspaces[0].Description) + }) } func TestCreateOrEditWorkspaceRepository(t *testing.T) { From 4983d1263ab490e34d439be4db506c60666f1a78 Mon Sep 17 00:00:00 2001 From: MuhammadUmer44 Date: Wed, 3 Jul 2024 17:00:27 +0500 Subject: [PATCH 3/5] Address write unit test GetUserDropdownWorkspaces --- db/db.go | 4 ---- handlers/workspaces.go | 2 +- handlers/workspaces_test.go | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/db/db.go b/db/db.go index b95fd5552..53bc968eb 100644 --- a/db/db.go +++ b/db/db.go @@ -1404,10 +1404,6 @@ func (db database) DeleteWorkSpaceAllData() error { return nil } -func (db database) DeleteWorkSpaceUserAccessData(pubKeyFromAuth string, uuid string, role string) bool { - return true -} - func (db database) GetPersonByPubkey(pubkey string) Person { m := Person{} db.db.Where("owner_pub_key = ? AND (deleted = false OR deleted is null)", pubkey).Find(&m) diff --git a/handlers/workspaces.go b/handlers/workspaces.go index 4ebb7d152..094a859ab 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -492,7 +492,7 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * uuid := value.WorkspaceUuid workspace := oh.db.GetWorkspaceByUuid(uuid) bountyCount := oh.db.GetWorkspaceBountyCount(uuid) - hasRole := oh.userHasAccess(user.OwnerPubKey, uuid, db.ViewReport) + hasRole := oh.db.UserHasAccess(user.OwnerPubKey, uuid, db.ViewReport) hasBountyRoles := oh.userHasManageBountyRoles(user.OwnerPubKey, uuid) // don't add deleted workspaces to the list diff --git a/handlers/workspaces_test.go b/handlers/workspaces_test.go index 7bcc42171..98dcc4793 100644 --- a/handlers/workspaces_test.go +++ b/handlers/workspaces_test.go @@ -1207,7 +1207,6 @@ func TestGetUserDropdownWorkspaces(t *testing.T) { db.TestDB.DeleteWorkSpaceAllData() oHandler := NewWorkspaceHandler(db.TestDB) - oHandler.userHasAccess = db.TestDB.DeleteWorkSpaceUserAccessData person := db.Person{ Uuid: uuid.New().String(), @@ -1245,6 +1244,7 @@ func TestGetUserDropdownWorkspaces(t *testing.T) { {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "UPDATE BOUNTY"}, {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "DELETE BOUNTY"}, {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "PAY BOUNTY"}, + {WorkspaceUuid: workspace.Uuid, OwnerPubKey: person2.OwnerPubKey, Role: "VIEW REPORT"}, } db.TestDB.CreateUserRoles(roles, workspace.Uuid, person2.OwnerPubKey) From 8738526fe42326fb4f4006225433362672432c4f Mon Sep 17 00:00:00 2001 From: MuhammadUmer44 Date: Thu, 4 Jul 2024 21:09:52 +0500 Subject: [PATCH 4/5] Address write unit test GetUserDropdownWorkspaces --- db/config.go | 21 +++++++++++++++++++++ handlers/workspaces.go | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/db/config.go b/db/config.go index cdece0150..e8f9e70b0 100644 --- a/db/config.go +++ b/db/config.go @@ -10,6 +10,16 @@ import ( "gorm.io/gorm" ) +type configHandler struct { + db Database +} + +func NewConfigHandler(database Database) *configHandler { + return &configHandler{ + db: database, + } +} + type database struct { db *gorm.DB getWorkspaceByUuid func(uuid string) Workspace @@ -389,6 +399,17 @@ func (db database) UserHasAccess(pubKeyFromAuth string, uuid string, role string return true } +func (ch configHandler) UserHasAccess(pubKeyFromAuth string, uuid string, role string) bool { + org := ch.db.GetWorkspaceByUuid(uuid) + var hasRole bool = false + if pubKeyFromAuth != org.OwnerPubKey { + userRoles := ch.db.GetUserRoles(uuid, pubKeyFromAuth) + hasRole = RolesCheck(userRoles, role) + return hasRole + } + return true +} + func (db database) UserHasManageBountyRoles(pubKeyFromAuth string, uuid string) bool { var manageRolesCount = len(ManageBountiesGroup) org := db.getWorkspaceByUuid(uuid) diff --git a/handlers/workspaces.go b/handlers/workspaces.go index 094a859ab..7b3be053b 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -21,17 +21,20 @@ type workspaceHandler struct { generateBountyHandler func(bounties []db.NewBounty) []db.BountyResponse getLightningInvoice func(payment_request string) (db.InvoiceResult, db.InvoiceError) userHasAccess func(pubKeyFromAuth string, uuid string, role string) bool + configUserHasAccess func(pubKeyFromAuth string, uuid string, role string) bool userHasManageBountyRoles func(pubKeyFromAuth string, uuid string) bool } func NewWorkspaceHandler(database db.Database) *workspaceHandler { bHandler := NewBountyHandler(http.DefaultClient, database) dbConf := db.NewDatabaseConfig(&gorm.DB{}) + configHandler := db.NewConfigHandler(database) return &workspaceHandler{ db: database, generateBountyHandler: bHandler.GenerateBountyResponse, getLightningInvoice: bHandler.GetLightningInvoice, userHasAccess: dbConf.UserHasAccess, + configUserHasAccess: configHandler.UserHasAccess, userHasManageBountyRoles: dbConf.UserHasManageBountyRoles, } } @@ -492,7 +495,7 @@ func (oh *workspaceHandler) GetUserDropdownWorkspaces(w http.ResponseWriter, r * uuid := value.WorkspaceUuid workspace := oh.db.GetWorkspaceByUuid(uuid) bountyCount := oh.db.GetWorkspaceBountyCount(uuid) - hasRole := oh.db.UserHasAccess(user.OwnerPubKey, uuid, db.ViewReport) + hasRole := oh.configUserHasAccess(user.OwnerPubKey, uuid, db.ViewReport) hasBountyRoles := oh.userHasManageBountyRoles(user.OwnerPubKey, uuid) // don't add deleted workspaces to the list @@ -518,7 +521,7 @@ func (oh *workspaceHandler) GetCreatedWorkspaces(pubkey string) []db.Workspace { for index, value := range workspaces { uuid := value.Uuid bountyCount := oh.db.GetWorkspaceBountyCount(uuid) - hasRole := oh.userHasAccess(pubkey, uuid, db.ViewReport) + hasRole := oh.configUserHasAccess(pubkey, uuid, db.ViewReport) if hasRole { budget := oh.db.GetWorkspaceBudget(uuid) From 7c088ee52528998241fc221af8c50e457a51a768 Mon Sep 17 00:00:00 2001 From: MuhammadUmer44 Date: Thu, 4 Jul 2024 21:34:07 +0500 Subject: [PATCH 5/5] fix UT --- handlers/workspaces.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/workspaces.go b/handlers/workspaces.go index 7b3be053b..d6643cb2b 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -1007,7 +1007,7 @@ func (oh *workspaceHandler) GetAllUserWorkspaces(pubkey string) []db.Workspace { uuid := value.WorkspaceUuid workspace := oh.db.GetWorkspaceByUuid(uuid) bountyCount := oh.db.GetWorkspaceBountyCount(uuid) - hasRole := db.UserHasAccess(pubkey, uuid, db.ViewReport) + hasRole := oh.configUserHasAccess(pubkey, uuid, db.ViewReport) // don't add deleted workspaces to the list if !workspace.Deleted { if hasRole {