diff options
| author | josh97josh | 2018-04-19 14:35:27 +0100 |
|---|---|---|
| committer | josh97josh | 2018-04-19 14:35:27 +0100 |
| commit | d201b19a53117afea306b0a2d96e28660f9f17d4 (patch) | |
| tree | f1141abcd60a6dbcefe49536ed9ec82418a016af /src | |
| parent | User privileges added on post (diff) | |
| download | medicine-d201b19a53117afea306b0a2d96e28660f9f17d4.tar.gz medicine-d201b19a53117afea306b0a2d96e28660f9f17d4.zip | |
Project Owners added
Diffstat (limited to 'src')
| -rw-r--r-- | src/FileRouter.ts | 87 | ||||
| -rw-r--r-- | src/db/model/ContributorGroup.ts | 12 | ||||
| -rw-r--r-- | src/db/model/Project.ts | 24 | ||||
| -rw-r--r-- | src/db/model/UserJoinsProject.ts | 7 |
4 files changed, 101 insertions, 29 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 746a13f..61f8262 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -14,6 +14,7 @@ import { Property, default as serverConfig } from './serverConfig'; import { uuid } from './uuid'; import UserHasPrivilege from './db/model/UserHasPrivilege'; import { Contains } from 'sequelize-typescript'; +import UserJoinsProject from './db/model/UserJoinsProject'; // TODO: figure this out const BASE_FILE_STORAGE: string = 'TODO: figure this out'; @@ -382,7 +383,9 @@ const postUsername: Middleware = async( name: req.body.privileges } }) - user.password = req.params.password; + if(user.password != null){ + user.password = req.params.password; + } if (req.body) { user.metadata = req.body; } @@ -537,25 +540,73 @@ const postProjectName: Middleware = async( let project: Project | null = res.locals.project; res.locals.modified = true; let promise: PromiseLike<File> | null = null; - if (project == null) { + + if( req.query.action === 'update'){ logger.debug('Adding new project'); - const file: File = new File({ - uuid: uuid.generate(), - mimetype: 'inode/directory' - }); - promise = file.save(); - project = new Project({ - name: req.params.project_name, - rootFolder: file - }); - } else { - logger.debug('Updating project properties'); + if(project != null){ + project.metadata = req.body; + await project.save() + } + else{ + next(new RequestError(400, 'project_not_found')); + } + } - project.metadata = req.body; - // tslint:disable-next-line:await-promise - await promise; - await project.save(); - next(); + else if( req.query.action === 'delete'){ + if(project != null){ + project.destroy() + } + else{ + next(new RequestError(400, 'project_not_found')); + } + } + else if( req.query.action === 'update_grant'){ + + } + else{ + if(project == null){ + logger.debug('Adding new project'); + const file: File = new File({ + uuid: uuid.generate(), + mimetype: 'inode/directory' + }); + promise = file.save(); + project = new Project({ + name: req.params.project_name, + rootFolder: file + }); + const owner: ContributorGroup | null = await ContributorGroup.findOne({ + include: [{all: true}], + where: { + name: 'projectOwner' + } + }) + //console.log(owner); + + project.metadata = req.body; + // tslint:disable-next-line:await-promise + await promise; + await project.save() + const contribute: UserJoinsProject = new UserJoinsProject({ + username: req.user.username, + projectName: req.params.project_name, + contributorGroupName: 'projectOwner' + + }) + contribute.save() + + console.log(contribute.contributorGroupName); + + // if (owner != undefined){ + // await contribute.$set('contributorGroupId', [owner]); + // } + } + else{ + next(new RequestError(400, 'project_already_exists')); + } + } + + next() }; /** diff --git a/src/db/model/ContributorGroup.ts b/src/db/model/ContributorGroup.ts index 637fc05..73bc558 100644 --- a/src/db/model/ContributorGroup.ts +++ b/src/db/model/ContributorGroup.ts @@ -1,12 +1,16 @@ -import { AllowNull, Column, DataType, HasMany, Model, Table +import { AllowNull, Column, DataType, HasMany, Model, Table, PrimaryKey } from 'sequelize-typescript'; import { default as UserJoinsProject } from './UserJoinsProject'; @Table export default class ContributorGroup extends Model<ContributorGroup> { - @AllowNull + @PrimaryKey @Column(DataType.TEXT) - public name!: string | null; + public name!: string; + + // @PrimaryKey + // @Column + // public username!: string; /* "Error: Foreign key for "ContributorGroup" * is missing on "UserJoinsProject"." */ @@ -33,7 +37,7 @@ export default class ContributorGroup extends Model<ContributorGroup> { @Column public canDeleteProject!: boolean; - + @AllowNull @Column(DataType.TEXT) diff --git a/src/db/model/Project.ts b/src/db/model/Project.ts index d57eaaa..41a70c9 100644 --- a/src/db/model/Project.ts +++ b/src/db/model/Project.ts @@ -88,15 +88,31 @@ export default class Project extends Model<Project> { return; } - public getAccessLevel(user: User): ContributorGroup { - throw new Error(`unimplemented, ${this}`); + public async getAccessLevel(user: User): Promise<String[]> { + const ujps: UserJoinsProject[] | null = await UserJoinsProject.findAll({ + include: [ ContributorGroup], + where: { + username: user.username, + projectName: this.name + } + }) + const people: String[] = ujps.map((ujp: UserJoinsProject): String => { + if(ujp.contributorGroup != undefined){ + console.log(ujp.contributorGroupName) + return ujp.contributorGroupName + } + else{ + throw new Error(`unimplemented, ${this}`); + } + }) + //console.log(people); + return await people; } public getUserInfo(user: User): UserInfo { return { username: user.username, - access_level: this.getAccessLevel(user) - .toString() + access_level: this.getAccessLevel(user).toString() }; } diff --git a/src/db/model/UserJoinsProject.ts b/src/db/model/UserJoinsProject.ts index 7ddb99e..7fe1bd6 100644 --- a/src/db/model/UserJoinsProject.ts +++ b/src/db/model/UserJoinsProject.ts @@ -14,13 +14,14 @@ export default class UserJoinsProject extends Model<UserJoinsProject> { @Column public projectName!: string; + @ForeignKey(() => ContributorGroup) + @Column + public contributorGroupName!: string; + @CreatedAt @Column(DataType.DATE) public joinDate!: Date; - @ForeignKey(() => ContributorGroup) - @Column - public contributorGroupId!: number; @BelongsTo(() => ContributorGroup) public contributorGroup?: ContributorGroup; |
