Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed Organization to Workspaces #1612

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading