Skip to content

Commit

Permalink
Merge pull request #1616 from AbdulWahab3181/feature/add-workspace-en…
Browse files Browse the repository at this point in the history
…dpoints

Add Endpoints and properties to Workspaces/Organizations
  • Loading branch information
elraphty authored Apr 26, 2024
2 parents 719d8e2 + 1f0316e commit d1fa4f1
Show file tree
Hide file tree
Showing 21 changed files with 2,722 additions and 1,042 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/docker-build-on-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ env:

on:
push:
branch:
- master
branches:
- master

jobs:
build:
runs-on: ubuntu-20.04
name: Build and push Tribes image
name: Build and push Tribes image
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
Expand Down Expand Up @@ -44,6 +44,3 @@ jobs:
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--tag "${{ secrets.DOCKER_HUB_USER }}/sphinx-tribes:master" \
--output "type=registry" ./
18 changes: 9 additions & 9 deletions .github/workflows/frontend-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Cypress Frontend E2E tests
on:
pull_request:
branches:
- master
- "*"

jobs:
cypress-run:
Expand Down Expand Up @@ -39,10 +39,10 @@ jobs:
chmod 777 -R ./lnd;
chmod 777 -R ./proxy;
chmod 777 -R ./cln;
- name: Check for NODES
uses: nick-fields/retry@v2
with:
with:
timeout_minutes: 10
max_attempts: 3
command: |
Expand All @@ -53,12 +53,12 @@ jobs:
docker logs dave.sphinx
docker wait stack_relaysetup_1
cat stack/relay/NODES.json;
- name: Copy Node.json
uses: canastro/copy-file-action@master
with:
source: 'stack/relay/NODES.json'
target: 'tribes-frontend/cypress/fixtures/nodes.json'
source: "stack/relay/NODES.json"
target: "tribes-frontend/cypress/fixtures/nodes.json"

- name: Install Frontend Dependencies
working-directory: ./tribes-frontend
Expand All @@ -73,14 +73,14 @@ jobs:
run: |
sleep 20
yarn run cypress:run
- name: Upload Cypress logs
if: failure()
uses: actions/upload-artifact@v2
with:
name: cypress-logs
path: tribes-frontend/cypress/videos

- name: Stop Stack
working-directory: ./stack
run: docker-compose down
run: docker-compose down
2 changes: 1 addition & 1 deletion .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Tests
on:
pull_request:
branches:
- master
- "*"
jobs:
test-go:
name: Go
Expand Down
3 changes: 3 additions & 0 deletions cypress/e2e/01_workspaces.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Edit Mission', () => {
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[0].uuid,
owner_pubkey: Workspaces[0].owner_pubkey,
mission: 'This is a sample mission for workspace'
}
}).then((resp) => {
Expand All @@ -59,6 +60,7 @@ describe('Edit Tactics', () => {
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[0].uuid,
owner_pubkey: Workspaces[0].owner_pubkey,
mission: 'This is a sample tactics and objectives for workspace'
}
}).then((resp) => {
Expand All @@ -79,6 +81,7 @@ describe('Edit Schematics Url', () => {
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[0].uuid,
owner_pubkey: Workspaces[0].owner_pubkey,
mission: 'This is a sample schematic url for workspaces'
}
}).then((resp) => {
Expand Down
117 changes: 104 additions & 13 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

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

func NewDatabaseConfig(db *gorm.DB) *database {
Expand Down Expand Up @@ -65,17 +65,12 @@ func InitDB() {
db.AutoMigrate(&Channel{})
db.AutoMigrate(&LeaderBoard{})
db.AutoMigrate(&ConnectionCodes{})
db.AutoMigrate(&Bounty{})
db.AutoMigrate(&Organization{})
db.AutoMigrate(&OrganizationUsers{})
db.AutoMigrate(&BountyRoles{})
db.AutoMigrate(&UserRoles{})
db.AutoMigrate(&BountyBudget{})
db.AutoMigrate(&BudgetHistory{})
db.AutoMigrate(&PaymentHistory{})
db.AutoMigrate(&InvoiceList{})
db.AutoMigrate(&UserInvoiceData{})

DB.MigrateTablesWithOrgUuid()
DB.MigrateOrganizationToWorkspace()

people := DB.GetAllPeople()
for _, p := range people {
if p.Uuid == "" {
Expand Down Expand Up @@ -178,6 +173,102 @@ func (db database) GetRolesCount() int64 {
return count
}

func (db database) MigrateTablesWithOrgUuid() {
if !db.db.Migrator().HasTable("bounty") {
if !db.db.Migrator().HasColumn(Bounty{}, "workspace_uuid") {
db.db.AutoMigrate(&Bounty{})
}
}
if !db.db.Migrator().HasTable("budget_histories") {
if !db.db.Migrator().HasColumn(BudgetHistory{}, "workspace_uuid") {
db.db.AutoMigrate(&BudgetHistory{})
}
}
if !db.db.Migrator().HasTable("payment_histories") {
if !db.db.Migrator().HasColumn(PaymentHistory{}, "workspace_uuid") {
db.db.AutoMigrate(&PaymentHistory{})
}
}
if !db.db.Migrator().HasTable("invoice_list") {
if !db.db.Migrator().HasColumn(InvoiceList{}, "workspace_uuid") {
db.db.AutoMigrate(&InvoiceList{})
}
}
if !db.db.Migrator().HasTable("bounty_budgets") {
if !db.db.Migrator().HasColumn(BountyBudget{}, "workspace_uuid") {
db.db.AutoMigrate(&BountyBudget{})
}
}
if !db.db.Migrator().HasTable("workspace_user_roles") {
if !db.db.Migrator().HasColumn(UserRoles{}, "workspace_uuid") {
db.db.AutoMigrate(&UserRoles{})
}
} else {
db.db.AutoMigrate(&WorkspaceUserRoles{})
}
if !db.db.Migrator().HasTable("workspaces") {
db.db.AutoMigrate(&Organization{})
} else {
db.db.AutoMigrate(&Workspace{})
}
if !db.db.Migrator().HasTable("workspace_users") {
db.db.AutoMigrate(&OrganizationUsers{})
} else {
db.db.AutoMigrate(&WorkspaceUsers{})
}
}

func (db database) MigrateOrganizationToWorkspace() {
if (db.db.Migrator().HasTable(&Organization{}) && !db.db.Migrator().HasTable("workspaces")) {
db.db.Migrator().RenameTable(&Organization{}, "workspaces")
}

if (db.db.Migrator().HasTable(&OrganizationUsers{}) && !db.db.Migrator().HasTable("workspace_users")) {
if db.db.Migrator().HasColumn(&OrganizationUsers{}, "org_uuid") {
db.db.Migrator().RenameColumn(&OrganizationUsers{}, "org_uuid", "workspace_uuid")
}
db.db.Migrator().RenameTable(&OrganizationUsers{}, "workspace_users")
}

if (db.db.Migrator().HasTable(&UserRoles{}) && !db.db.Migrator().HasTable("workspace_user_roles")) {
if db.db.Migrator().HasColumn(&UserRoles{}, "org_uuid") {
db.db.Migrator().RenameColumn(&UserRoles{}, "org_uuid", "workspace_uuid")
}

db.db.Migrator().RenameTable(&UserRoles{}, "workspace_user_roles")
}

if (db.db.Migrator().HasTable(&Bounty{})) {
if db.db.Migrator().HasColumn(&Bounty{}, "org_uuid") {
db.db.Migrator().RenameColumn(&Bounty{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&BountyBudget{})) {
if db.db.Migrator().HasColumn(&BountyBudget{}, "org_uuid") {
db.db.Migrator().RenameColumn(&BountyBudget{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&BudgetHistory{})) {
if db.db.Migrator().HasColumn(&BudgetHistory{}, "org_uuid") {
db.db.Migrator().RenameColumn(&BudgetHistory{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&PaymentHistory{})) {
if db.db.Migrator().HasColumn(&PaymentHistory{}, "org_uuid") {
db.db.Migrator().RenameColumn(&PaymentHistory{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&InvoiceList{})) {
if db.db.Migrator().HasColumn(&InvoiceList{}, "org_uuid") {
db.db.Migrator().RenameColumn(&InvoiceList{}, "org_uuid", "workspace_uuid")
}
}
}

func (db database) CreateRoles() {
db.db.Create(&ConfigBountyRoles)
}
Expand Down Expand Up @@ -205,7 +296,7 @@ func GetRolesMap() map[string]string {
return roles
}

func GetUserRolesMap(userRoles []UserRoles) map[string]string {
func GetUserRolesMap(userRoles []WorkspaceUserRoles) map[string]string {
roles := map[string]string{}
for _, v := range userRoles {
roles[v.Role] = v.Role
Expand Down Expand Up @@ -235,7 +326,7 @@ func (db database) ConvertMetricsBountiesToMap(metricsCsv []MetricsBountyCsv) []
return metricsMap
}

func RolesCheck(userRoles []UserRoles, check string) bool {
func RolesCheck(userRoles []WorkspaceUserRoles, check string) bool {
rolesMap := GetRolesMap()
userRolesMap := GetUserRolesMap(userRoles)

Expand All @@ -253,7 +344,7 @@ func RolesCheck(userRoles []UserRoles, check string) bool {
return true
}

func CheckUser(userRoles []UserRoles, pubkey string) bool {
func CheckUser(userRoles []WorkspaceUserRoles, pubkey string) bool {
for _, role := range userRoles {
if role.OwnerPubKey == pubkey {
return true
Expand Down
Loading

0 comments on commit d1fa4f1

Please sign in to comment.