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

feat: collaborators #510

Merged
merged 12 commits into from
Oct 4, 2022
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
46 changes: 27 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@tsconfig/recommended": "^1.0.1",
"@types/express": "^4.17.13",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.186",
"@types/node": "^17.0.21",
"@types/supertest": "^2.0.11",
"@types/validator": "^13.7.1",
Expand Down
5 changes: 5 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export enum SiteStatus {
Launched = "LAUNCHED",
}

export enum CollaboratorRoles {
Admin = "ADMIN",
Contributor = "CONTRIBUTOR",
}

export const E2E_ISOMER_ID = "-1"
export const E2E_TEST_EMAIL = "test@e2e"
export const E2E_TEST_CONTACT = "12345678"
59 changes: 59 additions & 0 deletions src/database/migrations/20220811070630-change-role-enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
async up(queryInterface, Sequelize) {
// Change the role enum values in the site_members table
await queryInterface.sequelize.transaction(async (transaction) => {
// 1. Change column type to TEXT
await queryInterface.changeColumn(
"site_members", // name of Source model
"role", // name of column we're modifying
{
type: Sequelize.TEXT,
},
{ transaction }
)
// 2. Discard enum type
await queryInterface.sequelize.query(
"drop type enum_site_members_role;",
{ transaction }
)
// 3. Change column type to new enum type (fails if inconsistent with existing data)
await queryInterface.changeColumn(
"site_members", // name of Source model
"role", // name of column we're modifying
{
type: Sequelize.ENUM("ADMIN", "CONTRIBUTOR"),
},
{ transaction }
)
})
},

async down(queryInterface, Sequelize) {
// Change the role enum values in the site_members table
await queryInterface.sequelize.transaction(async (transaction) => {
// 1. Change column type to TEXT
await queryInterface.changeColumn(
"site_members", // name of Source model
"role", // name of column we're modifying
{
type: Sequelize.TEXT,
},
{ transaction }
)
// 2. Discard enum type
await queryInterface.sequelize.query(
"drop type enum_site_members_role;",
{ transaction }
)
// 3. Change column type to new enum type (fails if inconsistent with existing data)
await queryInterface.changeColumn(
"site_members", // name of Source model
"role", // name of column we're modifying
{
type: Sequelize.ENUM("ADMIN", "USER"),
},
{ transaction }
)
})
},
}
3 changes: 2 additions & 1 deletion src/database/models/Site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Site extends Model {
@Column({
allowNull: false,
type: DataType.TEXT,
unique: true,
})
name!: string

Expand Down Expand Up @@ -70,7 +71,7 @@ export class Site extends Model {
through: () => SiteMember,
as: "site_members",
})
users!: User[]
site_members!: Array<User & { SiteMember: SiteMember }>

@HasOne(() => Repo)
repo?: Repo
Expand Down
6 changes: 4 additions & 2 deletions src/database/models/SiteMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
UpdatedAt,
} from "sequelize-typescript"

import { CollaboratorRoles } from "@constants/index"

import { Site } from "@database/models/Site"
import { User } from "@database/models/User"

Expand All @@ -23,9 +25,9 @@ export class SiteMember extends Model {

@Column({
allowNull: false,
type: DataType.ENUM("ADMIN", "USER"),
type: DataType.ENUM("ADMIN", "CONTRIBUTOR"),
})
role!: boolean
role!: CollaboratorRoles

@CreatedAt
createdAt!: Date
Expand Down
2 changes: 1 addition & 1 deletion src/database/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class User extends Model {
through: () => SiteMember,
as: "site_members",
})
sites!: Site[]
sites!: Array<Site & { SiteMember: SiteMember }>

@HasMany(() => Site, {
as: "sites_created",
Expand Down
4 changes: 2 additions & 2 deletions src/errors/ForbiddenError.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
const { BaseIsomerError } = require("@errors/BaseError")

class ForbiddenError extends BaseIsomerError {
constructor() {
super(403, "Access forbidden")
constructor(message) {
super(403, message || "Access forbidden")
}
}

Expand Down
Loading