Skip to content

Commit

Permalink
Merge pull request #1612 from stakwork/feat/org_to_workspace
Browse files Browse the repository at this point in the history
Renamed Organization to Workspaces
  • Loading branch information
elraphty authored Apr 15, 2024
2 parents c2bffde + 7dd3304 commit b43c477
Show file tree
Hide file tree
Showing 21 changed files with 1,673 additions and 1,663 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ packages:
We are currently using `gopkg.in/go-playground/validator.v9` for validation, to validate a struct add the `validate` property to it

```golang
type Organization struct {
type Workspace struct {
Name string `gorm:"unique;not null" json:"name" validate:"required"`
Website string `json:"website" validate:"omitempty,uri"`
Github string `json:"github" validate:"omitempty,uri"`
Expand Down
20 changes: 10 additions & 10 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
)

type database struct {
db *gorm.DB
getOrganizationByUuid func(uuid string) Organization
getUserRoles func(uuid string, pubkey string) []UserRoles
db *gorm.DB
getWorkspaceByUuid func(uuid string) Organization
getUserRoles func(uuid string, pubkey string) []UserRoles
}

func NewDatabaseConfig(db *gorm.DB) *database {
return &database{
db: db,
getOrganizationByUuid: DB.GetOrganizationByUuid,
getUserRoles: DB.GetUserRoles,
db: db,
getWorkspaceByUuid: DB.GetWorkspaceByUuid,
getUserRoles: DB.GetUserRoles,
}
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func (db database) ConvertMetricsBountiesToMap(metricsCsv []MetricsBountyCsv) []
metricMap := make(map[string]interface{})

metricMap["DatePosted"] = m.DatePosted
metricMap["Organization"] = m.Organization
metricMap["Workspace"] = m.Organization
metricMap["BountyAmount"] = m.BountyAmount
metricMap["Provider"] = m.Provider
metricMap["Hunter"] = m.Hunter
Expand Down Expand Up @@ -263,7 +263,7 @@ func CheckUser(userRoles []UserRoles, pubkey string) bool {
}

func UserHasAccess(pubKeyFromAuth string, uuid string, role string) bool {
org := DB.GetOrganizationByUuid(uuid)
org := DB.GetWorkspaceByUuid(uuid)
var hasRole bool = false
if pubKeyFromAuth != org.OwnerPubKey {
userRoles := DB.GetUserRoles(uuid, pubKeyFromAuth)
Expand All @@ -274,7 +274,7 @@ func UserHasAccess(pubKeyFromAuth string, uuid string, role string) bool {
}

func (db database) UserHasAccess(pubKeyFromAuth string, uuid string, role string) bool {
org := db.getOrganizationByUuid(uuid)
org := db.getWorkspaceByUuid(uuid)
var hasRole bool = false
if pubKeyFromAuth != org.OwnerPubKey {
userRoles := db.getUserRoles(uuid, pubKeyFromAuth)
Expand All @@ -286,7 +286,7 @@ func (db database) UserHasAccess(pubKeyFromAuth string, uuid string, role string

func (db database) UserHasManageBountyRoles(pubKeyFromAuth string, uuid string) bool {
var manageRolesCount = len(ManageBountiesGroup)
org := db.getOrganizationByUuid(uuid)
org := db.getWorkspaceByUuid(uuid)
if pubKeyFromAuth != org.OwnerPubKey {
userRoles := db.getUserRoles(uuid, pubKeyFromAuth)

Expand Down
8 changes: 4 additions & 4 deletions db/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestCheckUser(t *testing.T) {
}

func TestUserHasAccess(t *testing.T) {
mockGetOrganizationByUuid := func(uuid string) Organization {
mockGetWorkspaceByUuid := func(uuid string) Organization {
return Organization{
Uuid: uuid,
OwnerPubKey: "org_admin",
Expand All @@ -71,7 +71,7 @@ func TestUserHasAccess(t *testing.T) {
mockDB := &gorm.DB{}

databaseConfig := NewDatabaseConfig(mockDB)
databaseConfig.getOrganizationByUuid = mockGetOrganizationByUuid
databaseConfig.getWorkspaceByUuid = mockGetWorkspaceByUuid
databaseConfig.getUserRoles = mockGetUserRoles

t.Run("Should test that if the user is the admin of an organization returns true", func(t *testing.T) {
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestUserHasAccess(t *testing.T) {
}

func TestUserHasManageBountyRoles(t *testing.T) {
mockGetOrganizationByUuid := func(uuid string) Organization {
mockGetWorkspaceByUuid := func(uuid string) Organization {
return Organization{
Uuid: uuid,
OwnerPubKey: "org_admin",
Expand All @@ -128,7 +128,7 @@ func TestUserHasManageBountyRoles(t *testing.T) {
mockDB := &gorm.DB{}

databaseConfig := NewDatabaseConfig(mockDB)
databaseConfig.getOrganizationByUuid = mockGetOrganizationByUuid
databaseConfig.getWorkspaceByUuid = mockGetWorkspaceByUuid
databaseConfig.getUserRoles = mockGetUserRoles

t.Run("Should test that if the user is the organization admin return true", func(t *testing.T) {
Expand Down
Loading

0 comments on commit b43c477

Please sign in to comment.