diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/FileRouter.ts | 1041 | ||||
| -rw-r--r-- | src/app.ts | 59 | ||||
| -rw-r--r-- | src/auth.ts | 120 | ||||
| -rw-r--r-- | src/db/db.sql | 832 | ||||
| -rw-r--r-- | src/db/initPostgresDB.ts | 27 | ||||
| -rw-r--r-- | src/db/model/ContributorGroup.ts | 73 | ||||
| -rw-r--r-- | src/db/model/File.ts | 66 | ||||
| -rw-r--r-- | src/db/model/Project.ts | 111 | ||||
| -rw-r--r-- | src/db/model/User.ts | 122 | ||||
| -rw-r--r-- | src/db/model/UserGroup.ts | 67 | ||||
| -rw-r--r-- | src/db/model/UserJoinsProject.ts | 33 | ||||
| -rw-r--r-- | src/db/orm.ts | 4 | ||||
| -rw-r--r-- | src/index.ts | 93 | ||||
| -rw-r--r-- | src/matcher/options.test.ts | 258 | ||||
| -rw-r--r-- | src/matcher/options.ts | 155 | ||||
| -rw-r--r-- | src/matcher/types.test.ts | 178 | ||||
| -rw-r--r-- | src/matcher/types.ts | 107 | ||||
| -rw-r--r-- | src/serverConfig.ts | 174 |
18 files changed, 1915 insertions, 1605 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 423c1a7..34738bc 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -1,491 +1,568 @@ -import {Router, Request, Response, NextFunction} from 'express'; -import {default as UserGroup} from './db/model/UserGroup'; -import {default as User} from './db/model/User'; +import { ContributorGroupFullInfo, default as ContributorGroup + } from './db/model/ContributorGroup'; import { default as File } from './db/model/File'; -import Project from './db/model/Project'; -import ContributorGroup from './db/model/ContributorGroup'; - -var serverConfig = require('./serverConfig'); -const Files = null;//require('../data'); -const BASE_FILE_STORAGE: string = __dirname + '/storage'; +import { ProjectFullInfo, default as Project } from './db/model/Project'; +import { UserFullInfo, default as User } from './db/model/User'; +import { default as UserGroup } from './db/model/UserGroup'; + +import { NextFunction, Request, Response, Router } from 'express'; +import { default as serverConfig } from './serverConfig'; + +// TODO: figure this out +const BASE_FILE_STORAGE: string = 'TODO: figure this out'; + +/** + * The type of an Express middleware callback. + */ +type Middleware = + (req: Request, res: Response, next: NextFunction) => void; + +/** + * Returns the supported Protocols + * + * The server's unwrapped response MUST match: + * + * exactly({ + * "supported": array(string), + * "required": array(string) + * }) + */ +const getProtocols: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + const returnValue: { + supported: string[]; + required: string[]; + } = { + supported: [], + required: [ + 'BE01' + ] + }; + res.send(JSON.stringify(returnValue)); +}; + +/** + * Logging Endpoint for all components: + * + * with a request matching + * + * array({ + * "component": string, + * "level": alternative([ + * "info", + * "security", + * "warning", + * "error", + * "critical" + * ]), + * "value": anything + * }) + */ +const postLog: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.status(501) + .send({error : 'logging_not_enabled'}); +}; + +/** + * Clients authorised as a user with the admin privilege can access + * + * http://backend.endpoint/log?before=<datetime>&after=<datetime>&level=<level> + * + * the server response should match + * + * array({ + * "component": string, + * "level": alternative([ + * "info", + * "security", + * "warning", + * "error", + * "critical" + * ]), + * "value": anything, + * "username": string, + * "timestamp": string + * }) + */ +const getLog: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.status(501) + .send({error : 'logging_not_enabled'}); +}; + +/** + * Any authenticated client can access + * + * http://backend.endpoint/properties + * + * the server SHOULD respond with a list of properties, + * with the unwrapped response matching + * + * array({ + * "id": string, + * "display": optional({ + * "category": string, + * "group": string, + * "display_name": string, + * "description": string + * }), + * "read_only": boolean, + * "type": alternative(["string", "integer", "boolean"]), + * "value": alternative([string, integer, boolean]) + * }) + */ +const getProperties: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.status(200) + .send(serverConfig); +}; + +/** + * To update properties the client POSTs to + * + * http://backend.endpoint/properties?action=update + * + * with body + * + * array({ + * "id": string, + * "value": alternative([string, integer, boolean]) + * }) + */ +const postProperties: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + let success: boolean = true; + + // For each property to update + for (const prop of req.body) { + + // Check that the property has and id and a value + if (!prop.hasOwnProperty('id') || !prop.hasOwnProperty('value')) { + res.status(400) + .send({ + error: 'invalid_request', + error_description: 'A supplied property is missing an id or value' + }); + success = false; + break; + } + + // Find out if the property exists in the config and if so, at which index + const index: number = serverConfig.indexOf(prop.id); + + // Check some of the properties values to ensure that it can be updated + if (index === -1 || serverConfig[index].readOnly) { + /* TODO Implement an or, using Tom's type checker + * to ensure the value is "valid" based on the type of the property */ + const description: string = index === -1 + ? 'Property not found' + : 'Property is Read_Only'; + res.status(400) + .send({ + error: 'invalid_property', + error_data: prop.id, + error_description: description + }); + success = false; + break; + } + + // Make the update to the property + serverConfig[index].value = prop.value; + } + + // Tell the client that everything was okay; + if (success) { + res.status(200) + .send(); + } +}; + +/** + * Listing available privileges + * + * And the server's response, unwrapped, must match + * + * array({ + * "privilege": string, + * "description": string, + * "internal": boolean + * }) + */ +const getUserPriveleges: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const usergroups: UserGroup[] = await UserGroup.findAll(); + res.json(usergroups.map( + (ug: UserGroup) => ug.getPrivelege() + )); +}; + +/** + * Listing users + * + * If the client is authorised as a user with the admin privilege + * the server MUST respond with a list of users, + * with the unwrapped response matching + * + * array({ + * "username": string, + * "privileges": array(string), + * "projects": array({ + * "project_name": string, + * "access_level": string + * }), + * "public_user_metadata": metadata, + * "private_user_metadata": metadata, + * "public_admin_metadata": metadata, + * "private_admin_metadata": metadata + * }) + */ +const getUsers: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const users: User[] = await User.findAll({ + include: [ + UserGroup, + Project + ] + }); + res.json(users.map<UserFullInfo>( + (u: User) => u.getUserFullInfo() + )); +}; + +/** + * Expose additional configuration options for individual users + */ +const getUserProperties: Middleware = + (req: Request, res: Response, next: NextFunction, user?: string): void => { + res.status(500) + .send({ + error: 'unsupported', + error_description: + 'Users on this server dont have additional configuration options.' + }); +}; + +const userInfoFromName: (name: string) => Promise<UserFullInfo> = + async(name: string): Promise<UserFullInfo> => { + const user: User | null = await User.findOne({ + where: { + username: name + }, + include: [ + UserGroup, + Project + ] + }); + + if (user === null) { + throw new Error(`No user of name ${name} in database.`); + } else { + return user.getUserFullInfo(); + } +}; + +/** + * Listing a particular User + * + * If the client is authorised as a user with the admin privilege + * the server MUST respond with details of the particular user if they exist + * (unwrapped response): + * + * { + * "username": string, + * "privileges": array(string), + * "projects": array({ + * "project_name": string, + * "access_level": string + * }), + * "public_user_metadata": metadata, + * "private_user_metadata": metadata, + * "public_admin_metadata": metadata, + * "private_admin_metadata": metadata + * } + */ +const getUsername: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const info: UserFullInfo = await userInfoFromName(req.params.username); + res.json(info); +}; + +const getCurUser: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.json({ + todo: 'need to findo out where authenticated user info goes' + }); +}; + +/** + * Updating the current user + * + * http://backend.endpoint/current_user?action=update + * + * with body matching + * + * { + * "password": optional({ + * "old": string, + * "new": string + * }), + * "public_user_metadata": optional(metadata), + * "private_user_metadata": optional(metadata), + * "public_admin_metadata": not_present, + * "private_admin_metadata": not_present + * } + */ +const postCurUser: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.json({todo: 'need to implement meeeee'}); +}; + +/** + * Creating a User/updating a user + * + * http://backend.endpoint/users/<username>?action=create + * + * with body matching + * + * { + * "privileges": array(string), + * "password": string, + * "public_user_metadata": optional(metadata), + * "private_user_metadata": optional(metadata), + * "public_admin_metadata": optional(metadata), + * "private_admin_metadata": optional(metadata) + * } + */ +const postUsername: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.json({todo: 'need to implement meeeee'}); +}; + +/** + * Listing available Roles + * + * The servers response, unwrapped, must match + * + * array({ + * "role": string, + * "description": string, + * "internal": boolean + * }) + */ +const getProjectRoles: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const roles: ContributorGroup[] = await ContributorGroup.findAll(); + res.json(roles.map<ContributorGroupFullInfo>( + (cg: ContributorGroup) => cg.getContributorGroupFullInfo() + )); +}; + +/** + * Listing Projects + * + * The server MUST respond with a list of projects, + * with the unwrapped response matching + * + * array({ + * "project_name": string, + * "users": array({ + * "username": string, + * "access_level": string + * }), + * "public_metadata": metadata, + * "private_metadata": optional(metadata), + * "admin_metadata": optional(metadata) + * }) + */ +const getProjects: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const projects: Project[] = await Project.findAll({ + include: [ + User + ] + }); + res.json(projects.map<ProjectFullInfo>( + (p: Project) => p.getProjectFullInfo() + )); +}; + +/** + * Listing a specific Project + * + * The server MUST respond with details of the particular project + * if it exists (unwrapped response): + * + * { + * "project_name": string, + * "users": array({ + * "username": string, + * "access_level": string + * }), + * "public_metadata": metadata, + * "private_metadata": metadata, + * "admin_metadata": optional(metadata) + * } + */ +const getProjectName: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const project: Project | null = await Project.findOne({ + where: { + name: req.params.project_name + } + }); + if (project === null) { + throw new Error(`Project ${req.params.project_name} does not exist`); + } else { + res.json(project); + } +}; + +/** + * Creating a Project / updating a project / deleting / Project grants + * + * http://backend.endpoint/projects/<project_name>?action=create + * + * with body matching + * + * { + * "public_metadata": optional(metadata), + * "private_metadata": optional(metadata), + * "admin_metadata": optional(metadata) + * } + */ +const postProjectName: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.json({todo: 'need to implement meeeee'}); +}; + +/* + * additional configuration options for individual projects + */ +const getProjectProperties: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.status(500) + .send({ + error: 'unsupported', + error_description: + 'Projects on this server dont have additional configuration options.' + }); +}; + +const getChildFile: (names: string[], parentUuid: string) => Promise<File> = + async(names: string[], parentUuid: string): Promise<File> => { + // TODO: Check that this works lol :3 + const child: File | null = await File.findOne({ + where: { + parentFolderId: parentUuid, + name: names[0] + } + }); + + if (child === null) { + throw new Error(`File of name ${names[0]} does not exist`); + } else { + if (names.length === 1) { + return child; + } else { + names.splice(0, 1); + return getChildFile(names, child.uuid); + } + } +}; + +/** + * GET a File. + */ +const getFilePath: Middleware = + async(req: Request, res: Response, next: NextFunction): Promise<void> => { + const project: Project | null = await Project.findOne({ + where: { + name: req.params.project_name + } + }); + + if (project === null) { + throw new Error( + `Project of name ${req.params.project_name} does not exist` + ); + } else { + const file: File = await getChildFile( + req.params.project_name, project.rootFolderId + ); + + res.sendFile( + `${BASE_FILE_STORAGE}/${req.params.project_name}/${file.uuid}` + ); + } +}; + +/** + * GET a File. + */ +const getFileId: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + // TODO: implement correctness of project folder checking. + res.sendFile( + `${BASE_FILE_STORAGE}/${req.params.project_name}/${req.params.id}` + ); +}; + +/** + * Post a File. / delete / move / etc + */ +const postFilePath: Middleware = + (req: Request, res: Response, next: NextFunction): void => { + res.json({todo: 'need to implement meeeee'}); +}; export class FileRouter { - router: Router - - /** - * Initialize the FileRouter - */ - constructor() { - this.router = Router(); - this.init(); - } - - /* - * Returns the supported Protocols - * - * The server's unwrapped response MUST match: - - exactly({ - "supported": array(string), - "required": array(string) - }) - */ - public getProtocols(req: Request, res: Response, next: NextFunction){ - var returnValue = { - supported: [], - required: [ - "BE01" - ] - }; - res.send(JSON.stringify(returnValue)); - } - - /* - * Logging Endpoint for all components: - * - * with a request matching - - array({ - "component": string, - "level": alternative(["info", "security", "warning", "error", "critical"]), - "value": anything - }) - */ - public postLog(req: Request, res: Response, next: NextFunction){ - res.status(501).send({error : "logging_not_enabled"}); - } - - /* - * Clients authorised as a user with the admin privilege can access - * - * http://backend.endpoint/log?before=<datetime>&after=<datetime>&level=<level> - * - * the server response should match - - array({ - "component": string, - "level": alternative(["info", "security", "warning", "error", "critical"]), - "value": anything, - "username": string, - "timestamp": string - }) - */ - public getLog(req: Request, res: Response, next: NextFunction){ - res.status(501).send({error : "logging_not_enabled"}); - } - - /* - * Any authenticated client can access - * - * http://backend.endpoint/properties - * - * the server SHOULD respond with a list of properties, with the unwrapped response matching - - array({ - "id": string, - "display": optional({ - "category": string, - "group": string, - "display_name": string, - "description": string - }), - "read_only": boolean, - "type": alternative(["string", "integer", "boolean"]), - "value": alternative([string, integer, boolean]) - }) - */ - public getProperties(req: Request, res: Response, next: NextFunction){ - res.status(200).send(serverConfig.default); - } - - /* - * To update properties the client POSTs to - * - * http://backend.endpoint/properties?action=update - * - * with body - - array({ - "id": string, - "value": alternative([string, integer, boolean]) - }) - */ - public postProperties(req: Request, res: Response, next: NextFunction){ - var success = true; - - //For each property to update - for (var prop of req.body) { - - //Check that the property has and id and a value - if (!prop.hasOwnProperty("id") || !prop.hasOwnProperty("value")) { - res.status(400).send({error : "invalid_request", error_description : "A supplied property is missing an id or value"}); - success = false; - break; - } - - //Find out if the property exists in the config and if so, at which index - var index = serverConfig.propertyExists(prop.id); - - //check some of the properties values to ensure that it can be updated - if (index == -1 || serverConfig.default[index].read_only) { /*TODO Implement an or, using Tom's type checker to ensure the value is "valid" based on the type of the property */ - var description = index == -1 ? "Property not found" : "Property is Read_Only"; - res.status(400).send({error : "invalid_property", error_data : prop.id, error_description : description}); - success = false; - break; - } - - //make the update to the property - serverConfig.default[index].value = prop.value; - } - - //tell the client that everything was okay; - if (success) res.status(200).send(); - } - - /* - * Listing available privileges - * - * And the server's response, unwrapped, must match - - array({ - "privilege": string, - "description": string, - "internal": boolean - }) - */ - public getUserPriveleges(req: Request, res: Response, next: NextFunction){ - UserGroup.findAll() - .then((permissions) => { - res.json(permissions.map<any>( - (p: UserGroup) => p.getPrivelege() - )); - }); - } - - /* - * Listing users - * - * If the client is authorised as a user with the admin privilege - * the server MUST respond with a list of users, with the unwrapped response matching - - array({ - "username": string, - "privileges": array(string), - "projects": array({ - "project_name": string, - "access_level": string - }), - "public_user_metadata": metadata, - "private_user_metadata": metadata, - "public_admin_metadata": metadata, - "private_admin_metadata": metadata - }) - */ - public getUsers(req: Request, res: Response, next: NextFunction){ - User.findAll({ - include: [ - UserGroup, - Project - ] - }).then((user) => { - res.json(user.map<any>( - (u: User) => u.getUserFullInfo() - )); - }); - } - - /* - * expose additional configuration options for individual users - * - * - */ - public getUserProperties(req: Request, res: Response, next: NextFunction, user?: String){ - res.status(500).send({error: "unsupported", error_description: "Users on this server dont have additional configuration options."}); - } - - private async userInfoFromName(name: string) { - let user: User = await User.findOne({ - where: { - username: name - }, - include: [ - UserGroup, - Project - ] - }); - - return user.getUserFullInfo(); - } - - /* - * Listing a particular User - * - * If the client is authorised as a user with the admin privilege the server MUST respond with details of the particular user if they exist (unwrapped response): - - { - "username": string, - "privileges": array(string), - "projects": array({ - "project_name": string, - "access_level": string - }), - "public_user_metadata": metadata, - "private_user_metadata": metadata, - "public_admin_metadata": metadata, - "private_admin_metadata": metadata - } - */ - public getUsername(req: Request, res: Response, next: NextFunction, user?: String){ - this.userInfoFromName(req.params.username) - .then((info) => res.json(info)); - } - - public getCurUser(req: Request, res: Response, next: NextFunction){ - // TODO need to findo out where authenticated user info goes - // this.userInfoFromName(req.params.username) - // .then((info) => res.json(info)); - res.json({todo: "need to findo out where authenticated user info goes"}); - } - - /* - * Updating the current user - * - * http://backend.endpoint/current_user?action=update - * - * with body matching - - { - "password": optional({ - "old": string, - "new": string - }), - "public_user_metadata": optional(metadata), - "private_user_metadata": optional(metadata), - "public_admin_metadata": not_present, - "private_admin_metadata": not_present - } - */ - public postCurUser(req: Request, res: Response, next: NextFunction){ - res.json({todo: "need to implement meeeee"}); - } - - /* - * Creating a User/updating a user - * - * http://backend.endpoint/users/<username>?action=create - * - * with body matching - - { - "privileges": array(string), - "password": string, - "public_user_metadata": optional(metadata), - "private_user_metadata": optional(metadata), - "public_admin_metadata": optional(metadata), - "private_admin_metadata": optional(metadata) - } - */ - public postUsername(req: Request, res: Response, next: NextFunction){ - res.json({todo: "need to implement meeeee"}); - } - - /* - * Listing available Roles - * - * The servers response, unwrapped, must match - - array({ - "role": string, - "description": string, - "internal": boolean - }) - */ - public getProjectRoles(req: Request, res: Response, next: NextFunction){ - ContributorGroup.findAll() - .then((cgs: ContributorGroup[]) => { - res.json(cgs.map<any>( - (cg: ContributorGroup) => cg.getGroupFullInfo() - )); - }); - } - - /* - * Listing Projects - * - * The server MUST respond with a list of projects, with the unwrapped response matching - - array({ - "project_name": string, - "users": array({ - "username": string, - "access_level": string - }), - "public_metadata": metadata, - "private_metadata": optional(metadata), - "admin_metadata": optional(metadata) - }) - */ - public getProjects(req: Request, res: Response, next: NextFunction){ - Project.findAll({ - include: [ - User - ] - }).then((projects) => { - res.json(projects.map<any>( - (p: Project) => p.getProjectFullInfo() - )); - }); - } - - /* - * Listing a specific Project - * - * The server MUST respond with details of the particular project if it exists (unwrapped response): - - { - "project_name": string, - "users": array({ - "username": string, - "access_level": string - }), - "public_metadata": metadata, - "private_metadata": metadata, - "admin_metadata": optional(metadata) - } - */ - public getProjectName(req: Request, res: Response, next: NextFunction){ - Project.findOne({ - where: { - name: req.params.project_name - } - }).then((project: Project) => res.json(project)); - - } - - /* - * Creating a Project / updating a project / deleting / Project grants - * - * http://backend.endpoint/projects/<project_name>?action=create - * - * with body matching - - { - "public_metadata": optional(metadata), - "private_metadata": optional(metadata), - "admin_metadata": optional(metadata) - } - */ - public postProjectName(req: Request, res: Response, next: NextFunction){ - res.json({todo: "need to implement meeeee"}); - } - - /* - * additional configuration options for individual projects - */ - public getProjectProperties(req: Request, res: Response, next: NextFunction){ - res.status(500).send({error: "unsupported", error_description: "Projects on this server dont have additional configuration options."}); - } - - private async getChildFile(names: string[], parentUuid: string): Promise<File> { - //TODO: Check that this works lol :3 - let child: File = await File.findOne({ - where: { - parentFolderId: parentUuid, - name: names[0] - } - }); - if (names.length === 1) { - return child; - } else { - names.splice(0, 1); - return await this.getChildFile(names, child.uuid); - } - } - - /** - * GET a File. - */ - public async getFile_path(req: Request, res: Response, next: NextFunction) { - req.params.project_name - req.params.path - - let project: Project = await Project.findOne({ - where: { - name: req.params.project_name - } - }); - - let file: File = await this.getChildFile( - req.params.project_name, project.rootFolderId); - - res.sendFile(`${BASE_FILE_STORAGE}/${req.params.project_name}/${file.uuid}`); - } - - /** - * GET a File. - */ - public getFile_id(req: Request, res: Response, next: NextFunction) { - - //TODO: implement correctness of project folder checking. - res.sendFile(`${BASE_FILE_STORAGE}/${req.params.project_name}/${req.params.id}`); - } - - - - - - - - - - - - - - /** - * Post a File. / delete / move / etc - */ - public postFile_path(req: Request, res: Response, next: NextFunction) { - res.json({todo: "need to implement meeeee"}); - } - - - /** - * Take each handler, and attach to one of the Express.Router's - * endpoints. - */ - init() { - // General - this.router.get ('/_supported_protocols_', this.getProtocols); - this.router.get ('/log', this.getLog); - this.router.post('/log', this.postLog); - this.router.get ('/properties', this.getProperties); - this.router.post('/properties', this.postProperties); - // Users - this.router.get ('/user_privileges', this.getUserPriveleges); - this.router.get ('/users', this.getUsers); - this.router.get ('/users/:username', this.getUsername); - this.router.post('/users/:username', this.postUsername); - this.router.get ('/users/:username/properties', this.getUserProperties); - this.router.get ('/current_user', this.getCurUser); - this.router.post('/current_user', this.postCurUser); - // Projects - this.router.get ('/project_roles', this.getProjectRoles); - this.router.get ('/projects', this.getProjects); - this.router.get ('/projects/:project_name', this.getProjectName); - this.router.post('/projects/:project_name', this.postProjectName); - this.router.get ('/projects/:project_name/properties', this.getProjectProperties); - // File access - this.router.get ('/projects/:project_name/files/:path', this.getFile_path); - this.router.post('/projects/:project_name/files/:id', this.postFile_path); - this.router.get ('/projects/:project_name/files_by_id/:id', this.getFile_id); - } - + public router: Router; + + /** + * Initialize the FileRouter + */ + public constructor() { + this.router = Router(); + this.init(); + } + + /** + * Take each handler, and attach to one of the Express.Router's + * endpoints. + */ + public init(): void { + // General + this.router.get ('/_supported_protocols_', getProtocols); + this.router.get ('/log', getLog); + this.router.post('/log', postLog); + this.router.get ('/properties', getProperties); + this.router.post('/properties', postProperties); + // Users + this.router.get ('/user_privileges', getUserPriveleges); + this.router.get ('/users', getUsers); + this.router.get ('/users/:username', getUsername); + this.router.post('/users/:username', postUsername); + this.router.get ('/users/:username/properties', getUserProperties); + this.router.get ('/current_user', getCurUser); + this.router.post('/current_user', postCurUser); + // Projects + this.router.get ('/project_roles', getProjectRoles); + this.router.get ('/projects', getProjects); + this.router.get ('/projects/:project_name', getProjectName); + this.router.post('/projects/:project_name', postProjectName); + this.router.get ('/projects/:project_name/properties', getProjectProperties); + // File access + this.router.get ('/projects/:project_name/files/:path', getFilePath); + this.router.post('/projects/:project_name/files/:id', postFilePath); + this.router.get ('/projects/:project_name/files_by_id/:id', getFileId); + } } // Create the FileRouter, and export its configured Express.Router -const fileRoutes = new FileRouter(); +const fileRoutes: FileRouter = new FileRouter(); fileRoutes.init(); -var ex: Router = fileRoutes.router; +const ex: Router = fileRoutes.router; export default ex; @@ -1,38 +1,39 @@ -import * as express from 'express'; -import * as logger from 'morgan'; import * as bodyParser from 'body-parser'; +import * as ex from 'express'; import FileRouter from './FileRouter'; - +import * as logger from 'morgan'; class App { - public express - public log_enabled : boolean; + public express: ex.Express; + public logEnabled: boolean = true; - constructor () { - this.express = express() - this.middleware() - this.mountRoutes() - } + public constructor() { + this.express = ex(); + this.middleware(); + this.mountRoutes(); + } - // Configure Express middleware. - private middleware(): void { - if(this.log_enabled) this.express.use(logger('combined')); - this.express.use(bodyParser.json()); - this.express.use(bodyParser.urlencoded({ extended: false })); - } + // Configure Express middleware. + private middleware(): void { + if (this.logEnabled) { + this.express.use(logger('combined')); + } + this.express.use(bodyParser.json()); + this.express.use(bodyParser.urlencoded({ extended: false })); + } - // Configure API endpoints. - private mountRoutes (): void { - const defRouter = express.Router() - defRouter.get('/', (req, res) => { - res.json({ - message: 'Welcome to the CS3099 BE4 server!', - important : 'Endpoints start from /cs3099group-be-4/' - }) - }) - this.express.use('/', defRouter) - this.express.use('/cs3099group-be-4', FileRouter) - } + // Configure API endpoints. + private mountRoutes(): void { + const defRouter: ex.Router = ex.Router(); + defRouter.get('/', (req: ex.Request, res: ex.Response): void => { + res.json({ + message: 'Welcome to the CS3099 BE4 server!', + important : 'Endpoints start from /cs3099group-be-4/' + }); + }); + this.express.use('/', defRouter); + this.express.use('/cs3099group-be-4', FileRouter); + } } -export default new App().express +export default new App().express; diff --git a/src/auth.ts b/src/auth.ts index 3e2dafe..a59e417 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,67 +1,70 @@ -import * as passport from 'passport'; -import * as passportLocal from 'passport-local'; -import * as jwt from 'jsonwebtoken'; -import {Router, Request, Response, NextFunction} from 'express'; +import { NextFunction, Request, Response, Router } from 'express'; import * as expressJwt from 'express-jwt'; +import * as jwt from 'jsonwebtoken'; +import * as passport from 'passport'; +import { Strategy } from 'passport-local'; +import { default as User } from './db/model/User'; export class AuthRouter { - LocalStrategy: any - router: Router + public localStrategy: Strategy; + public router: Router; - constructor() { - this.LocalStrategy = passportLocal.Strategy(); + public constructor() { + this.localStrategy = Strategy(); this.router(); this.init(); } - //Used by passport-js to locate a user object from the database by username - public findByUsername(username) { - if (username == user.username) { + // Used by passport-js to locate a user object from the database by username + public findByUsername(username: string): User { + if (username === user.username) { return user; } return false; } - //Find user obejct from database by user ID - public findUserByID(id) { - if (id == user.id) { + // Find user object from database by user ID + public findUserByID(id): User { + if (id === user.id) { return user; } return false; } - //middleware which generates token and sends it as response - public genToken(req: Request, res: Response) { - var userid = findUserByID(req.body.username); - - var token = jwt.sign({ - id: userid - }, 'Mr Secret', { - expiresIn: 21600 - }); + // Middleware which generates token and sends it as response + public genToken(req: Request, res: Response) { + const userid = findUserByID(req.body.username); + const token = jwt.sign( + { id: userid }, + 'Mr Secret', + { expiresIn: 21600 } + ); res.json({ - "token_type": "bearer", - "access_token": token, - "refresh_token": token, - "expires_in": 21600 + token_type: 'bearer', + access_token: token, + refresh_token: token, + expires_in: 21600 }); } - //checks for errors within request before authentication - public checkErr(req: Request, res: Response, next: NextFunction) { + // Checks for errors within request before authentication + public checkErr(req: Request, res: Response, next: NextFunction) { if (!req.body.grant_type || !req.body.username || !req.body.password) { - res.status(400).json({ - "error": "invalid_request", - "error_description": "Missing parameters" - }); - res.end(); + res.status(400) + .json({ + error: 'invalid_request', + error_description: 'Missing parameters' + }); + res.end(); } - if (req.body.grant_type != "refresh_token" && req.body.grant_type != "password") { - res.status(400).json({ - "error": "unsupported_grant_type", - "error_description": "invalid grant type" + if (req.body.grant_type !== 'refresh_token' + && req.body.grant_type !== 'password') { + res.status(400) + .json({ + error: 'unsupported_grant_type', + error_description: 'invalid grant type' }); res.end(); } @@ -69,26 +72,26 @@ export class AuthRouter { next(); } - //handle error if user is unauthorised + // Handle error if user is unauthorised public unauthorisedErr(err, req: Request, res: Response, next: NextFunction) { - console.log(err); if (err.name === 'UnauthorizedError') { res.status(401).json({ - "status": "error", - "error": "not_authorised", - "error_description": "user does not have correct authorisation to complete task" - }); + status: 'error', + error: 'not_authorised', + error_description: + 'user does not have correct authorisation to complete task' + }); } next(); } - //Configure local strategy to use with passport-js. + // Configure local strategy to use with passport-js. private configStrategy() { - passport.use(new LocalStrategy( (username, password, done) => { - var user = findByUsername(username); + passport.use(new localStrategy( (username, password, done) => { + const user = findByUsername(username); - if (!user || user.password != password) { - return done(null, false); + if (!user || user.password != password) { + return done(null, false); } return done(null, user); })); @@ -96,35 +99,34 @@ export class AuthRouter { } /////////////////////////////////////////////////// -var app = express(); -var ensureAuth = expressJwt({secret: 'Mr Secret'}); //protect routes +const app = express(); +const ensureAuth = expressJwt({secret: 'Mr Secret'}); //protect routes app.use(passport.initialize()); app.use(unauthorisedErr); //currently does not handle userdefined error -app.post('/login', checkErr, function(req, res, next) { +app.post('/login', checkErr, function(req, res, next) { passport.authenticate('local', { session: false }, function(err, user) { - if (err) { console.log(err); } + if (err) { console.log(err); } if (!user) { res.status(400).json({ - "error": "invalid_grant", - "error_description": "Incorrect authentication details" + error: 'invalid_grant', + error_description: 'Incorrect authentication details' }); - } + } }); next(); -}, genToken); +}, genToken); app.get('/logout', function(req, res) { req.logout(); }); app.get('/test', ensureAuth, function(req, res) { - res.send("you are authenticated!"); + res.send('you are authenticated!'); }); - /* tasks left: refreshing tokens diff --git a/src/db/db.sql b/src/db/db.sql index 771d362..45c2338 100644 --- a/src/db/db.sql +++ b/src/db/db.sql @@ -5,7 +5,7 @@ -- Dumped from database version 10.1 -- Dumped by pg_dump version 10.0 --- Started on 2018-02-07 00:18:25 GMT +-- Started on 2018-02-07 18:20:04 GMT SET statement_timeout = 0; SET lock_timeout = 0; @@ -17,7 +17,7 @@ SET client_min_messages = warning; SET row_security = off; -- --- TOC entry 9 (class 2615 OID 17274) +-- TOC entry 10 (class 2615 OID 17274) -- Name: project_permissions; Type: SCHEMA; Schema: -; Owner: joshlee -- @@ -27,7 +27,7 @@ CREATE SCHEMA project_permissions; ALTER SCHEMA project_permissions OWNER TO joshlee; -- --- TOC entry 7 (class 2615 OID 16582) +-- TOC entry 8 (class 2615 OID 16582) -- Name: user_permissions; Type: SCHEMA; Schema: -; Owner: joshlee -- @@ -45,7 +45,7 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; -- --- TOC entry 2727 (class 0 OID 0) +-- TOC entry 2776 (class 0 OID 0) -- Dependencies: 1 -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -- @@ -53,10 +53,27 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; +-- +-- TOC entry 2 (class 3079 OID 17619) +-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; + + +-- +-- TOC entry 2777 (class 0 OID 0) +-- Dependencies: 2 +-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions'; + + SET search_path = project_permissions, pg_catalog; -- --- TOC entry 233 (class 1255 OID 17515) +-- TOC entry 240 (class 1255 OID 17515) -- Name: add_permission(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee -- @@ -80,7 +97,7 @@ $_$; ALTER FUNCTION project_permissions.add_permission() OWNER TO joshlee; -- --- TOC entry 241 (class 1255 OID 17371) +-- TOC entry 254 (class 1255 OID 17371) -- Name: check_permission(text, text, text); Type: FUNCTION; Schema: project_permissions; Owner: joshlee -- @@ -100,7 +117,7 @@ $_$; ALTER FUNCTION project_permissions.check_permission(username text, permission text, project text) OWNER TO joshlee; -- --- TOC entry 237 (class 1255 OID 17281) +-- TOC entry 247 (class 1255 OID 17281) -- Name: prevent_edit(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee -- @@ -121,7 +138,7 @@ $$; ALTER FUNCTION project_permissions.prevent_edit() OWNER TO joshlee; -- --- TOC entry 250 (class 1255 OID 17279) +-- TOC entry 275 (class 1255 OID 17279) -- Name: prevent_owner_delete(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee -- @@ -153,7 +170,7 @@ $_$; ALTER FUNCTION project_permissions.prevent_owner_delete() OWNER TO joshlee; -- --- TOC entry 244 (class 1255 OID 17280) +-- TOC entry 262 (class 1255 OID 17280) -- Name: prevent_undefined_project_grant(); Type: FUNCTION; Schema: project_permissions; Owner: joshlee -- @@ -187,7 +204,7 @@ ALTER FUNCTION project_permissions.prevent_undefined_project_grant() OWNER TO jo SET search_path = public, pg_catalog; -- --- TOC entry 235 (class 1255 OID 17312) +-- TOC entry 245 (class 1255 OID 17312) -- Name: give_owner_permissions(); Type: FUNCTION; Schema: public; Owner: joshlee -- @@ -218,7 +235,7 @@ $_$; ALTER FUNCTION public.give_owner_permissions() OWNER TO joshlee; -- --- TOC entry 254 (class 1255 OID 17577) +-- TOC entry 286 (class 1255 OID 17577) -- Name: set_user_permissions(); Type: FUNCTION; Schema: public; Owner: joshlee -- @@ -236,7 +253,7 @@ ALTER FUNCTION public.set_user_permissions() OWNER TO joshlee; SET search_path = user_permissions, pg_catalog; -- --- TOC entry 245 (class 1255 OID 17579) +-- TOC entry 269 (class 1255 OID 17579) -- Name: add_permission(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee -- @@ -254,7 +271,7 @@ $_$; ALTER FUNCTION user_permissions.add_permission() OWNER TO joshlee; -- --- TOC entry 257 (class 1255 OID 17370) +-- TOC entry 292 (class 1255 OID 17370) -- Name: check_permission(text, text); Type: FUNCTION; Schema: user_permissions; Owner: joshlee -- @@ -271,7 +288,7 @@ $_$; ALTER FUNCTION user_permissions.check_permission(username text, permission text) OWNER TO joshlee; -- --- TOC entry 240 (class 1255 OID 16907) +-- TOC entry 251 (class 1255 OID 16907) -- Name: prevent_admin_delete(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee -- @@ -290,7 +307,7 @@ $$; ALTER FUNCTION user_permissions.prevent_admin_delete() OWNER TO joshlee; -- --- TOC entry 242 (class 1255 OID 16911) +-- TOC entry 255 (class 1255 OID 16911) -- Name: prevent_edit(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee -- @@ -308,7 +325,7 @@ $$; ALTER FUNCTION user_permissions.prevent_edit() OWNER TO joshlee; -- --- TOC entry 249 (class 1255 OID 16924) +-- TOC entry 274 (class 1255 OID 16924) -- Name: prevent_undefined_grant(); Type: FUNCTION; Schema: user_permissions; Owner: joshlee -- @@ -327,7 +344,7 @@ $$; ALTER FUNCTION user_permissions.prevent_undefined_grant() OWNER TO joshlee; -- --- TOC entry 255 (class 1255 OID 16726) +-- TOC entry 288 (class 1255 OID 16726) -- Name: userexists(text); Type: FUNCTION; Schema: user_permissions; Owner: joshlee -- @@ -349,7 +366,7 @@ ALTER FUNCTION user_permissions.userexists(usertocheck text) OWNER TO joshlee; SET search_path = public, pg_catalog; -- --- TOC entry 220 (class 1259 OID 17314) +-- TOC entry 219 (class 1259 OID 17314) -- Name: af_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -370,7 +387,7 @@ SET default_tablespace = ''; SET default_with_oids = false; -- --- TOC entry 211 (class 1259 OID 17030) +-- TOC entry 210 (class 1259 OID 17030) -- Name: add_files; Type: TABLE; Schema: project_permissions; Owner: joshlee -- @@ -387,7 +404,7 @@ ALTER TABLE add_files OWNER TO joshlee; SET search_path = public, pg_catalog; -- --- TOC entry 221 (class 1259 OID 17317) +-- TOC entry 220 (class 1259 OID 17317) -- Name: ef_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -404,7 +421,7 @@ ALTER TABLE ef_id_seq OWNER TO joshlee; SET search_path = project_permissions, pg_catalog; -- --- TOC entry 212 (class 1259 OID 17086) +-- TOC entry 211 (class 1259 OID 17086) -- Name: edit_files; Type: TABLE; Schema: project_permissions; Owner: joshlee -- @@ -419,7 +436,7 @@ CREATE TABLE edit_files ( ALTER TABLE edit_files OWNER TO joshlee; -- --- TOC entry 231 (class 1259 OID 17475) +-- TOC entry 230 (class 1259 OID 17475) -- Name: project_permissions_list; Type: TABLE; Schema: project_permissions; Owner: joshlee -- @@ -438,7 +455,7 @@ ALTER TABLE project_permissions_list OWNER TO joshlee; SET search_path = public, pg_catalog; -- --- TOC entry 222 (class 1259 OID 17320) +-- TOC entry 221 (class 1259 OID 17320) -- Name: rf_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -455,7 +472,7 @@ ALTER TABLE rf_id_seq OWNER TO joshlee; SET search_path = project_permissions, pg_catalog; -- --- TOC entry 213 (class 1259 OID 17110) +-- TOC entry 212 (class 1259 OID 17110) -- Name: remove_files; Type: TABLE; Schema: project_permissions; Owner: joshlee -- @@ -472,7 +489,7 @@ ALTER TABLE remove_files OWNER TO joshlee; SET search_path = public, pg_catalog; -- --- TOC entry 224 (class 1259 OID 17326) +-- TOC entry 223 (class 1259 OID 17326) -- Name: vf_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -489,7 +506,7 @@ ALTER TABLE vf_id_seq OWNER TO joshlee; SET search_path = project_permissions, pg_catalog; -- --- TOC entry 214 (class 1259 OID 17158) +-- TOC entry 213 (class 1259 OID 17158) -- Name: view_files; Type: TABLE; Schema: project_permissions; Owner: joshlee -- @@ -506,45 +523,7 @@ ALTER TABLE view_files OWNER TO joshlee; SET search_path = public, pg_catalog; -- --- TOC entry 200 (class 1259 OID 16447) --- Name: folder; Type: TABLE; Schema: public; Owner: joshlee --- - -CREATE TABLE folder ( - object_id integer NOT NULL, - folder_name pg_catalog.text DEFAULT '"new folder"'::pg_catalog.text -); - - -ALTER TABLE folder OWNER TO joshlee; - --- --- TOC entry 199 (class 1259 OID 16445) --- Name: Folder _id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee --- - -CREATE SEQUENCE "Folder _id_seq" - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE "Folder _id_seq" OWNER TO joshlee; - --- --- TOC entry 2732 (class 0 OID 0) --- Dependencies: 199 --- Name: Folder _id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: joshlee --- - -ALTER SEQUENCE "Folder _id_seq" OWNED BY folder.object_id; - - --- --- TOC entry 225 (class 1259 OID 17329) +-- TOC entry 224 (class 1259 OID 17329) -- Name: cp_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -559,7 +538,7 @@ CREATE SEQUENCE cp_id_seq ALTER TABLE cp_id_seq OWNER TO joshlee; -- --- TOC entry 226 (class 1259 OID 17332) +-- TOC entry 225 (class 1259 OID 17332) -- Name: cu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -574,26 +553,25 @@ CREATE SEQUENCE cu_id_seq ALTER TABLE cu_id_seq OWNER TO joshlee; -- --- TOC entry 210 (class 1259 OID 16969) +-- TOC entry 209 (class 1259 OID 16969) -- Name: dirent; Type: TABLE; Schema: public; Owner: joshlee -- CREATE TABLE dirent ( - object_id integer NOT NULL, - super_folder integer, - project_name pg_catalog.text + project_name pg_catalog.text, + "UUID" uuid DEFAULT gen_random_uuid() NOT NULL, + super_folder uuid ); ALTER TABLE dirent OWNER TO joshlee; -- --- TOC entry 209 (class 1259 OID 16967) --- Name: dirent_object_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee +-- TOC entry 226 (class 1259 OID 17335) +-- Name: eu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- -CREATE SEQUENCE dirent_object_id_seq - AS integer +CREATE SEQUENCE eu_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -601,31 +579,20 @@ CREATE SEQUENCE dirent_object_id_seq CACHE 1; -ALTER TABLE dirent_object_id_seq OWNER TO joshlee; - --- --- TOC entry 2734 (class 0 OID 0) --- Dependencies: 209 --- Name: dirent_object_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: joshlee --- - -ALTER SEQUENCE dirent_object_id_seq OWNED BY dirent.object_id; - +ALTER TABLE eu_id_seq OWNER TO joshlee; -- --- TOC entry 227 (class 1259 OID 17335) --- Name: eu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee +-- TOC entry 200 (class 1259 OID 16447) +-- Name: folder; Type: TABLE; Schema: public; Owner: joshlee -- -CREATE SEQUENCE eu_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; +CREATE TABLE folder ( + folder_name pg_catalog.text DEFAULT '"new folder"'::pg_catalog.text, + "UUID" uuid NOT NULL +); -ALTER TABLE eu_id_seq OWNER TO joshlee; +ALTER TABLE folder OWNER TO joshlee; -- -- TOC entry 201 (class 1259 OID 16494) @@ -633,9 +600,8 @@ ALTER TABLE eu_id_seq OWNER TO joshlee; -- CREATE TABLE image ( - object_id integer NOT NULL, image_name pg_catalog.text, - "UUID" uuid + "UUID" uuid NOT NULL ); @@ -672,14 +638,16 @@ CREATE SEQUENCE permission_seq ALTER TABLE permission_seq OWNER TO joshlee; -- --- TOC entry 198 (class 1259 OID 16396) +-- TOC entry 199 (class 1259 OID 16396) -- Name: project; Type: TABLE; Schema: public; Owner: joshlee -- CREATE TABLE project ( project_name pg_catalog.text NOT NULL, - "date created" date DEFAULT CURRENT_DATE, - owner pg_catalog.text NOT NULL + owner pg_catalog.text NOT NULL, + public_metadata json, + private_metadata json, + admin_metadata json ); @@ -701,7 +669,7 @@ CREATE SEQUENCE project_name ALTER TABLE project_name OWNER TO joshlee; -- --- TOC entry 223 (class 1259 OID 17323) +-- TOC entry 222 (class 1259 OID 17323) -- Name: rp_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -716,7 +684,7 @@ CREATE SEQUENCE rp_id_seq ALTER TABLE rp_id_seq OWNER TO joshlee; -- --- TOC entry 228 (class 1259 OID 17338) +-- TOC entry 227 (class 1259 OID 17338) -- Name: ru_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -736,9 +704,8 @@ ALTER TABLE ru_id_seq OWNER TO joshlee; -- CREATE TABLE text ( - object_id integer NOT NULL, text_name pg_catalog.text, - "UUID" uuid + "UUID" uuid NOT NULL ); @@ -751,7 +718,11 @@ ALTER TABLE text OWNER TO joshlee; CREATE TABLE "user" ( username pg_catalog.text NOT NULL, - password character(32) + password character(32), + public_user_metadata json, + private_user_metadata json, + public_admin_metadata json, + private_admin_metadata json ); @@ -773,7 +744,65 @@ CREATE SEQUENCE user_id_seq ALTER TABLE user_id_seq OWNER TO joshlee; -- --- TOC entry 229 (class 1259 OID 17341) +-- TOC entry 233 (class 1259 OID 17603) +-- Name: view_current_user; Type: VIEW; Schema: public; Owner: joshlee +-- + +CREATE VIEW view_current_user AS + SELECT "user".username, + "user".public_user_metadata, + "user".private_user_metadata, + "user".public_admin_metadata + FROM "user"; + + +ALTER TABLE view_current_user OWNER TO joshlee; + +-- +-- TOC entry 234 (class 1259 OID 17611) +-- Name: view_projects_public; Type: VIEW; Schema: public; Owner: joshlee +-- + +CREATE VIEW view_projects_public AS + SELECT project.project_name, + project.owner, + project.public_metadata + FROM project; + + +ALTER TABLE view_projects_public OWNER TO joshlee; + +-- +-- TOC entry 235 (class 1259 OID 17615) +-- Name: view_projects_regular; Type: VIEW; Schema: public; Owner: joshlee +-- + +CREATE VIEW view_projects_regular AS + SELECT project.project_name, + project.owner, + project.public_metadata, + project.private_metadata + FROM project; + + +ALTER TABLE view_projects_regular OWNER TO joshlee; + +-- +-- TOC entry 232 (class 1259 OID 17599) +-- Name: view_users_public; Type: VIEW; Schema: public; Owner: joshlee +-- + +CREATE VIEW view_users_public AS + SELECT "user".username, + "user".public_user_metadata, + "user".public_admin_metadata + FROM "user"; + + +ALTER TABLE view_users_public OWNER TO joshlee; + +-- +-- TOC entry 228 (class 1259 OID 17341) -- Name: vp_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -788,7 +817,7 @@ CREATE SEQUENCE vp_id_seq ALTER TABLE vp_id_seq OWNER TO joshlee; -- --- TOC entry 230 (class 1259 OID 17344) +-- TOC entry 229 (class 1259 OID 17344) -- Name: vu_id_seq; Type: SEQUENCE; Schema: public; Owner: joshlee -- @@ -805,7 +834,7 @@ ALTER TABLE vu_id_seq OWNER TO joshlee; SET search_path = user_permissions, pg_catalog; -- --- TOC entry 215 (class 1259 OID 17182) +-- TOC entry 214 (class 1259 OID 17182) -- Name: create_project; Type: TABLE; Schema: user_permissions; Owner: joshlee -- @@ -833,7 +862,7 @@ CREATE TABLE create_users ( ALTER TABLE create_users OWNER TO joshlee; -- --- TOC entry 216 (class 1259 OID 17201) +-- TOC entry 215 (class 1259 OID 17201) -- Name: edit_users; Type: TABLE; Schema: user_permissions; Owner: joshlee -- @@ -847,7 +876,7 @@ CREATE TABLE edit_users ( ALTER TABLE edit_users OWNER TO joshlee; -- --- TOC entry 217 (class 1259 OID 17220) +-- TOC entry 216 (class 1259 OID 17220) -- Name: remove_users; Type: TABLE; Schema: user_permissions; Owner: joshlee -- @@ -861,7 +890,7 @@ CREATE TABLE remove_users ( ALTER TABLE remove_users OWNER TO joshlee; -- --- TOC entry 232 (class 1259 OID 17533) +-- TOC entry 231 (class 1259 OID 17533) -- Name: user_permissions_list; Type: TABLE; Schema: user_permissions; Owner: joshlee -- @@ -879,7 +908,7 @@ CREATE TABLE user_permissions_list ( ALTER TABLE user_permissions_list OWNER TO joshlee; -- --- TOC entry 218 (class 1259 OID 17233) +-- TOC entry 217 (class 1259 OID 17233) -- Name: view_projects; Type: TABLE; Schema: user_permissions; Owner: joshlee -- @@ -893,7 +922,7 @@ CREATE TABLE view_projects ( ALTER TABLE view_projects OWNER TO joshlee; -- --- TOC entry 219 (class 1259 OID 17246) +-- TOC entry 218 (class 1259 OID 17246) -- Name: view_users; Type: TABLE; Schema: user_permissions; Owner: joshlee -- @@ -906,83 +935,60 @@ CREATE TABLE view_users ( ALTER TABLE view_users OWNER TO joshlee; -SET search_path = public, pg_catalog; - --- --- TOC entry 2426 (class 2604 OID 16972) --- Name: dirent object_id; Type: DEFAULT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY dirent ALTER COLUMN object_id SET DEFAULT nextval('dirent_object_id_seq'::regclass); - - --- --- TOC entry 2423 (class 2604 OID 16450) --- Name: folder object_id; Type: DEFAULT; Schema: public; Owner: joshlee --- - -ALTER TABLE ONLY folder ALTER COLUMN object_id SET DEFAULT nextval('"Folder _id_seq"'::regclass); - - SET search_path = project_permissions, pg_catalog; -- --- TOC entry 2697 (class 0 OID 17030) --- Dependencies: 211 +-- TOC entry 2746 (class 0 OID 17030) +-- Dependencies: 210 -- Data for Name: add_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee -- -INSERT INTO add_files VALUES ('josh', 35, NULL, 'project 1'); -- --- TOC entry 2698 (class 0 OID 17086) --- Dependencies: 212 +-- TOC entry 2747 (class 0 OID 17086) +-- Dependencies: 211 -- Data for Name: edit_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee -- -INSERT INTO edit_files VALUES ('josh', 30, NULL, 'project 1'); -- --- TOC entry 2717 (class 0 OID 17475) --- Dependencies: 231 +-- TOC entry 2766 (class 0 OID 17475) +-- Dependencies: 230 -- Data for Name: project_permissions_list; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee -- -INSERT INTO project_permissions_list VALUES ('josh', 35, 30, 31, 22, 'project 1'); -- --- TOC entry 2699 (class 0 OID 17110) --- Dependencies: 213 +-- TOC entry 2748 (class 0 OID 17110) +-- Dependencies: 212 -- Data for Name: remove_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee -- -INSERT INTO remove_files VALUES ('josh', 31, NULL, 'project 1'); -- --- TOC entry 2700 (class 0 OID 17158) --- Dependencies: 214 +-- TOC entry 2749 (class 0 OID 17158) +-- Dependencies: 213 -- Data for Name: view_files; Type: TABLE DATA; Schema: project_permissions; Owner: joshlee -- -INSERT INTO view_files VALUES ('josh', 22, NULL, 'project 1'); SET search_path = public, pg_catalog; -- --- TOC entry 2696 (class 0 OID 16969) --- Dependencies: 210 +-- TOC entry 2745 (class 0 OID 16969) +-- Dependencies: 209 -- Data for Name: dirent; Type: TABLE DATA; Schema: public; Owner: joshlee -- -- --- TOC entry 2686 (class 0 OID 16447) +-- TOC entry 2736 (class 0 OID 16447) -- Dependencies: 200 -- Data for Name: folder; Type: TABLE DATA; Schema: public; Owner: joshlee -- @@ -990,7 +996,7 @@ SET search_path = public, pg_catalog; -- --- TOC entry 2687 (class 0 OID 16494) +-- TOC entry 2737 (class 0 OID 16494) -- Dependencies: 201 -- Data for Name: image; Type: TABLE DATA; Schema: public; Owner: joshlee -- @@ -998,16 +1004,15 @@ SET search_path = public, pg_catalog; -- --- TOC entry 2684 (class 0 OID 16396) --- Dependencies: 198 +-- TOC entry 2735 (class 0 OID 16396) +-- Dependencies: 199 -- Data for Name: project; Type: TABLE DATA; Schema: public; Owner: joshlee -- -INSERT INTO project VALUES ('project 1', '2018-02-06', 'josh'); -- --- TOC entry 2688 (class 0 OID 16502) +-- TOC entry 2738 (class 0 OID 16502) -- Dependencies: 202 -- Data for Name: text; Type: TABLE DATA; Schema: public; Owner: joshlee -- @@ -1015,22 +1020,22 @@ INSERT INTO project VALUES ('project 1', '2018-02-06', 'josh'); -- --- TOC entry 2689 (class 0 OID 16552) +-- TOC entry 2739 (class 0 OID 16552) -- Dependencies: 203 -- Data for Name: user; Type: TABLE DATA; Schema: public; Owner: joshlee -- -INSERT INTO "user" VALUES ('admin', '21232f297a57a5a743894a0e4a801fc3'); -INSERT INTO "user" VALUES ('josh', 'f94adcc3ddda04a8f34928d862f404b4'); -INSERT INTO "user" VALUES ('user2', '7e58d63b60197ceb55a1c487989a3720'); -INSERT INTO "user" VALUES ('user3', '92877af70a45fd6a2ed7fe81e1236b78'); +INSERT INTO "user" VALUES ('admin', '21232f297a57a5a743894a0e4a801fc3', NULL, NULL, NULL, NULL); +INSERT INTO "user" VALUES ('josh', 'f94adcc3ddda04a8f34928d862f404b4', NULL, NULL, NULL, NULL); +INSERT INTO "user" VALUES ('user2', '7e58d63b60197ceb55a1c487989a3720', NULL, NULL, NULL, NULL); +INSERT INTO "user" VALUES ('user3', '92877af70a45fd6a2ed7fe81e1236b78', NULL, NULL, NULL, NULL); SET search_path = user_permissions, pg_catalog; -- --- TOC entry 2701 (class 0 OID 17182) --- Dependencies: 215 +-- TOC entry 2750 (class 0 OID 17182) +-- Dependencies: 214 -- Data for Name: create_project; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1038,7 +1043,7 @@ INSERT INTO create_project VALUES ('admin', 1, 1); -- --- TOC entry 2692 (class 0 OID 16887) +-- TOC entry 2742 (class 0 OID 16887) -- Dependencies: 206 -- Data for Name: create_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1047,8 +1052,8 @@ INSERT INTO create_users VALUES ('admin', 1, 1); -- --- TOC entry 2702 (class 0 OID 17201) --- Dependencies: 216 +-- TOC entry 2751 (class 0 OID 17201) +-- Dependencies: 215 -- Data for Name: edit_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1056,8 +1061,8 @@ INSERT INTO edit_users VALUES ('admin', 1, 1); -- --- TOC entry 2703 (class 0 OID 17220) --- Dependencies: 217 +-- TOC entry 2752 (class 0 OID 17220) +-- Dependencies: 216 -- Data for Name: remove_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1065,8 +1070,8 @@ INSERT INTO remove_users VALUES ('admin', 1, 1); -- --- TOC entry 2718 (class 0 OID 17533) --- Dependencies: 232 +-- TOC entry 2767 (class 0 OID 17533) +-- Dependencies: 231 -- Data for Name: user_permissions_list; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1076,8 +1081,8 @@ INSERT INTO user_permissions_list VALUES ('user3', NULL, NULL, NULL, NULL, NULL, -- --- TOC entry 2704 (class 0 OID 17233) --- Dependencies: 218 +-- TOC entry 2753 (class 0 OID 17233) +-- Dependencies: 217 -- Data for Name: view_projects; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1085,8 +1090,8 @@ INSERT INTO view_projects VALUES ('admin', 1, 1); -- --- TOC entry 2705 (class 0 OID 17246) --- Dependencies: 219 +-- TOC entry 2754 (class 0 OID 17246) +-- Dependencies: 218 -- Data for Name: view_users; Type: TABLE DATA; Schema: user_permissions; Owner: joshlee -- @@ -1096,26 +1101,17 @@ INSERT INTO view_users VALUES ('admin', 1, 1); SET search_path = public, pg_catalog; -- --- TOC entry 2746 (class 0 OID 0) --- Dependencies: 199 --- Name: Folder _id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('"Folder _id_seq"', 17, true); - - --- --- TOC entry 2747 (class 0 OID 0) --- Dependencies: 220 +-- TOC entry 2779 (class 0 OID 0) +-- Dependencies: 219 -- Name: af_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- -SELECT pg_catalog.setval('af_id_seq', 36, true); +SELECT pg_catalog.setval('af_id_seq', 37, true); -- --- TOC entry 2748 (class 0 OID 0) --- Dependencies: 225 +-- TOC entry 2780 (class 0 OID 0) +-- Dependencies: 224 -- Name: cp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1123,8 +1119,8 @@ SELECT pg_catalog.setval('cp_id_seq', 5, true); -- --- TOC entry 2749 (class 0 OID 0) --- Dependencies: 226 +-- TOC entry 2781 (class 0 OID 0) +-- Dependencies: 225 -- Name: cu_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1132,26 +1128,17 @@ SELECT pg_catalog.setval('cu_id_seq', 2, true); -- --- TOC entry 2750 (class 0 OID 0) --- Dependencies: 209 --- Name: dirent_object_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee --- - -SELECT pg_catalog.setval('dirent_object_id_seq', 60, true); - - --- --- TOC entry 2751 (class 0 OID 0) --- Dependencies: 221 +-- TOC entry 2782 (class 0 OID 0) +-- Dependencies: 220 -- Name: ef_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- -SELECT pg_catalog.setval('ef_id_seq', 31, true); +SELECT pg_catalog.setval('ef_id_seq', 32, true); -- --- TOC entry 2752 (class 0 OID 0) --- Dependencies: 227 +-- TOC entry 2783 (class 0 OID 0) +-- Dependencies: 226 -- Name: eu_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1159,7 +1146,7 @@ SELECT pg_catalog.setval('eu_id_seq', 3, true); -- --- TOC entry 2753 (class 0 OID 0) +-- TOC entry 2784 (class 0 OID 0) -- Dependencies: 208 -- Name: permission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1168,7 +1155,7 @@ SELECT pg_catalog.setval('permission_id_seq', 145, true); -- --- TOC entry 2754 (class 0 OID 0) +-- TOC entry 2785 (class 0 OID 0) -- Dependencies: 207 -- Name: permission_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1177,7 +1164,7 @@ SELECT pg_catalog.setval('permission_seq', 3, true); -- --- TOC entry 2755 (class 0 OID 0) +-- TOC entry 2786 (class 0 OID 0) -- Dependencies: 204 -- Name: project_name; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1186,17 +1173,17 @@ SELECT pg_catalog.setval('project_name', 1, true); -- --- TOC entry 2756 (class 0 OID 0) --- Dependencies: 222 +-- TOC entry 2787 (class 0 OID 0) +-- Dependencies: 221 -- Name: rf_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- -SELECT pg_catalog.setval('rf_id_seq', 32, true); +SELECT pg_catalog.setval('rf_id_seq', 33, true); -- --- TOC entry 2757 (class 0 OID 0) --- Dependencies: 223 +-- TOC entry 2788 (class 0 OID 0) +-- Dependencies: 222 -- Name: rp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1204,8 +1191,8 @@ SELECT pg_catalog.setval('rp_id_seq', 2, true); -- --- TOC entry 2758 (class 0 OID 0) --- Dependencies: 228 +-- TOC entry 2789 (class 0 OID 0) +-- Dependencies: 227 -- Name: ru_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1213,7 +1200,7 @@ SELECT pg_catalog.setval('ru_id_seq', 3, true); -- --- TOC entry 2759 (class 0 OID 0) +-- TOC entry 2790 (class 0 OID 0) -- Dependencies: 205 -- Name: user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1222,17 +1209,17 @@ SELECT pg_catalog.setval('user_id_seq', 3, true); -- --- TOC entry 2760 (class 0 OID 0) --- Dependencies: 224 +-- TOC entry 2791 (class 0 OID 0) +-- Dependencies: 223 -- Name: vf_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- -SELECT pg_catalog.setval('vf_id_seq', 23, true); +SELECT pg_catalog.setval('vf_id_seq', 24, true); -- --- TOC entry 2761 (class 0 OID 0) --- Dependencies: 229 +-- TOC entry 2792 (class 0 OID 0) +-- Dependencies: 228 -- Name: vp_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1240,8 +1227,8 @@ SELECT pg_catalog.setval('vp_id_seq', 3, true); -- --- TOC entry 2762 (class 0 OID 0) --- Dependencies: 230 +-- TOC entry 2793 (class 0 OID 0) +-- Dependencies: 229 -- Name: vu_id_seq; Type: SEQUENCE SET; Schema: public; Owner: joshlee -- @@ -1251,7 +1238,7 @@ SELECT pg_catalog.setval('vu_id_seq', 2, true); SET search_path = project_permissions, pg_catalog; -- --- TOC entry 2455 (class 2606 OID 17038) +-- TOC entry 2502 (class 2606 OID 17038) -- Name: add_files add_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1260,7 +1247,7 @@ ALTER TABLE ONLY add_files -- --- TOC entry 2457 (class 2606 OID 17094) +-- TOC entry 2504 (class 2606 OID 17094) -- Name: edit_files edit_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1269,7 +1256,7 @@ ALTER TABLE ONLY edit_files -- --- TOC entry 2473 (class 2606 OID 17512) +-- TOC entry 2520 (class 2606 OID 17512) -- Name: project_permissions_list project_permissions_list_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1278,7 +1265,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2459 (class 2606 OID 17118) +-- TOC entry 2506 (class 2606 OID 17118) -- Name: remove_files remove_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1287,7 +1274,7 @@ ALTER TABLE ONLY remove_files -- --- TOC entry 2461 (class 2606 OID 17166) +-- TOC entry 2508 (class 2606 OID 17166) -- Name: view_files view_files_pkey; Type: CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1298,34 +1285,34 @@ ALTER TABLE ONLY view_files SET search_path = public, pg_catalog; -- --- TOC entry 2441 (class 2606 OID 16452) --- Name: folder Folder _pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee +-- TOC entry 2500 (class 2606 OID 17665) +-- Name: dirent dirent_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee -- -ALTER TABLE ONLY folder - ADD CONSTRAINT "Folder _pkey" PRIMARY KEY (object_id); +ALTER TABLE ONLY dirent + ADD CONSTRAINT dirent_pkey PRIMARY KEY ("UUID"); -- --- TOC entry 2453 (class 2606 OID 16977) --- Name: dirent dirent_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee +-- TOC entry 2488 (class 2606 OID 17667) +-- Name: folder folder_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee -- -ALTER TABLE ONLY dirent - ADD CONSTRAINT dirent_pkey PRIMARY KEY (object_id); +ALTER TABLE ONLY folder + ADD CONSTRAINT folder_pkey PRIMARY KEY ("UUID"); -- --- TOC entry 2443 (class 2606 OID 16795) +-- TOC entry 2490 (class 2606 OID 17684) -- Name: image image_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee -- ALTER TABLE ONLY image - ADD CONSTRAINT image_pkey PRIMARY KEY (object_id); + ADD CONSTRAINT image_pkey PRIMARY KEY ("UUID"); -- --- TOC entry 2437 (class 2606 OID 16668) +-- TOC entry 2484 (class 2606 OID 16668) -- Name: project project_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee -- @@ -1334,7 +1321,7 @@ ALTER TABLE ONLY project -- --- TOC entry 2439 (class 2606 OID 16404) +-- TOC entry 2486 (class 2606 OID 16404) -- Name: project projects_project_name_key; Type: CONSTRAINT; Schema: public; Owner: joshlee -- @@ -1343,16 +1330,16 @@ ALTER TABLE ONLY project -- --- TOC entry 2445 (class 2606 OID 16797) +-- TOC entry 2492 (class 2606 OID 17686) -- Name: text text_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee -- ALTER TABLE ONLY text - ADD CONSTRAINT text_pkey PRIMARY KEY (object_id); + ADD CONSTRAINT text_pkey PRIMARY KEY ("UUID"); -- --- TOC entry 2447 (class 2606 OID 16562) +-- TOC entry 2494 (class 2606 OID 16562) -- Name: user user _username_key; Type: CONSTRAINT; Schema: public; Owner: joshlee -- @@ -1361,7 +1348,7 @@ ALTER TABLE ONLY "user" -- --- TOC entry 2449 (class 2606 OID 16770) +-- TOC entry 2496 (class 2606 OID 16770) -- Name: user user_pkey; Type: CONSTRAINT; Schema: public; Owner: joshlee -- @@ -1372,7 +1359,7 @@ ALTER TABLE ONLY "user" SET search_path = user_permissions, pg_catalog; -- --- TOC entry 2463 (class 2606 OID 17190) +-- TOC entry 2510 (class 2606 OID 17190) -- Name: create_project create_project_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1381,7 +1368,7 @@ ALTER TABLE ONLY create_project -- --- TOC entry 2451 (class 2606 OID 16950) +-- TOC entry 2498 (class 2606 OID 16950) -- Name: create_users create_user_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1390,7 +1377,7 @@ ALTER TABLE ONLY create_users -- --- TOC entry 2467 (class 2606 OID 17227) +-- TOC entry 2514 (class 2606 OID 17227) -- Name: remove_users remove_users_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1399,7 +1386,7 @@ ALTER TABLE ONLY remove_users -- --- TOC entry 2465 (class 2606 OID 17208) +-- TOC entry 2512 (class 2606 OID 17208) -- Name: edit_users untitled_table_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1408,7 +1395,7 @@ ALTER TABLE ONLY edit_users -- --- TOC entry 2475 (class 2606 OID 17540) +-- TOC entry 2522 (class 2606 OID 17540) -- Name: user_permissions_list user_permissions_list_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1417,7 +1404,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2469 (class 2606 OID 17240) +-- TOC entry 2516 (class 2606 OID 17240) -- Name: view_projects view_projects_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1426,7 +1413,7 @@ ALTER TABLE ONLY view_projects -- --- TOC entry 2471 (class 2606 OID 17253) +-- TOC entry 2518 (class 2606 OID 17253) -- Name: view_users view_users_pkey; Type: CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -1437,7 +1424,7 @@ ALTER TABLE ONLY view_users SET search_path = project_permissions, pg_catalog; -- --- TOC entry 2528 (class 2620 OID 17298) +-- TOC entry 2575 (class 2620 OID 17298) -- Name: add_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1445,7 +1432,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON add_files FOR EACH ROW EXECUTE P -- --- TOC entry 2533 (class 2620 OID 17302) +-- TOC entry 2580 (class 2620 OID 17302) -- Name: edit_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1453,7 +1440,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON edit_files FOR EACH ROW EXECUTE -- --- TOC entry 2535 (class 2620 OID 17305) +-- TOC entry 2582 (class 2620 OID 17305) -- Name: remove_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1461,7 +1448,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON remove_files FOR EACH ROW EXECUT -- --- TOC entry 2541 (class 2620 OID 17311) +-- TOC entry 2588 (class 2620 OID 17311) -- Name: view_files edit_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1469,7 +1456,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON view_files FOR EACH ROW EXECUTE -- --- TOC entry 2527 (class 2620 OID 17297) +-- TOC entry 2574 (class 2620 OID 17297) -- Name: add_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1477,7 +1464,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON add_files FOR EACH ROW EXECUTE -- --- TOC entry 2531 (class 2620 OID 17300) +-- TOC entry 2578 (class 2620 OID 17300) -- Name: edit_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1485,7 +1472,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON edit_files FOR EACH ROW EXECUTE -- --- TOC entry 2536 (class 2620 OID 17303) +-- TOC entry 2583 (class 2620 OID 17303) -- Name: remove_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1493,7 +1480,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON remove_files FOR EACH ROW EXECU -- --- TOC entry 2539 (class 2620 OID 17309) +-- TOC entry 2586 (class 2620 OID 17309) -- Name: view_files grant_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1501,7 +1488,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON view_files FOR EACH ROW EXECUTE -- --- TOC entry 2530 (class 2620 OID 17516) +-- TOC entry 2577 (class 2620 OID 17516) -- Name: add_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1509,7 +1496,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON add_files FOR EACH ROW EXECUTE -- --- TOC entry 2534 (class 2620 OID 17517) +-- TOC entry 2581 (class 2620 OID 17517) -- Name: edit_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1517,7 +1504,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON edit_files FOR EACH ROW EXECUTE -- --- TOC entry 2538 (class 2620 OID 17518) +-- TOC entry 2585 (class 2620 OID 17518) -- Name: remove_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1525,7 +1512,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON remove_files FOR EACH ROW EXECU -- --- TOC entry 2542 (class 2620 OID 17519) +-- TOC entry 2589 (class 2620 OID 17519) -- Name: view_files insert_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1533,7 +1520,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON view_files FOR EACH ROW EXECUTE -- --- TOC entry 2529 (class 2620 OID 17299) +-- TOC entry 2576 (class 2620 OID 17299) -- Name: add_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1541,7 +1528,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON add_files FOR EACH ROW EXECUTE -- --- TOC entry 2532 (class 2620 OID 17301) +-- TOC entry 2579 (class 2620 OID 17301) -- Name: edit_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1549,7 +1536,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON edit_files FOR EACH ROW EXECUT -- --- TOC entry 2537 (class 2620 OID 17304) +-- TOC entry 2584 (class 2620 OID 17304) -- Name: remove_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1557,7 +1544,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON remove_files FOR EACH ROW EXEC -- --- TOC entry 2540 (class 2620 OID 17310) +-- TOC entry 2587 (class 2620 OID 17310) -- Name: view_files remove_permission; Type: TRIGGER; Schema: project_permissions; Owner: joshlee -- @@ -1567,7 +1554,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON view_files FOR EACH ROW EXECUT SET search_path = public, pg_catalog; -- --- TOC entry 2519 (class 2620 OID 17313) +-- TOC entry 2566 (class 2620 OID 17313) -- Name: project add_project; Type: TRIGGER; Schema: public; Owner: joshlee -- @@ -1575,7 +1562,7 @@ CREATE TRIGGER add_project AFTER INSERT ON project FOR EACH ROW EXECUTE PROCEDUR -- --- TOC entry 2522 (class 2620 OID 17578) +-- TOC entry 2569 (class 2620 OID 17578) -- Name: user add_user; Type: TRIGGER; Schema: public; Owner: joshlee -- @@ -1583,7 +1570,7 @@ CREATE TRIGGER add_user AFTER INSERT ON "user" FOR EACH ROW EXECUTE PROCEDURE se -- --- TOC entry 2520 (class 2620 OID 16912) +-- TOC entry 2567 (class 2620 OID 16912) -- Name: user user_delete; Type: TRIGGER; Schema: public; Owner: joshlee -- @@ -1591,7 +1578,7 @@ CREATE TRIGGER user_delete BEFORE DELETE ON "user" FOR EACH ROW EXECUTE PROCEDUR -- --- TOC entry 2521 (class 2620 OID 16913) +-- TOC entry 2568 (class 2620 OID 16913) -- Name: user user_edit; Type: TRIGGER; Schema: public; Owner: joshlee -- @@ -1601,7 +1588,7 @@ CREATE TRIGGER user_edit BEFORE UPDATE ON "user" FOR EACH ROW EXECUTE PROCEDURE SET search_path = user_permissions, pg_catalog; -- --- TOC entry 2554 (class 2620 OID 17583) +-- TOC entry 2601 (class 2620 OID 17583) -- Name: remove_users add_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1609,7 +1596,7 @@ CREATE TRIGGER add_permission AFTER INSERT ON remove_users FOR EACH ROW EXECUTE -- --- TOC entry 2523 (class 2620 OID 16914) +-- TOC entry 2570 (class 2620 OID 16914) -- Name: create_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1617,7 +1604,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON create_users FOR EACH ROW EXECUT -- --- TOC entry 2543 (class 2620 OID 17284) +-- TOC entry 2590 (class 2620 OID 17284) -- Name: create_project edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1625,7 +1612,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON create_project FOR EACH ROW EXEC -- --- TOC entry 2548 (class 2620 OID 17287) +-- TOC entry 2595 (class 2620 OID 17287) -- Name: edit_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1633,7 +1620,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON edit_users FOR EACH ROW EXECUTE -- --- TOC entry 2552 (class 2620 OID 17290) +-- TOC entry 2599 (class 2620 OID 17290) -- Name: remove_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1641,7 +1628,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON remove_users FOR EACH ROW EXECUT -- --- TOC entry 2556 (class 2620 OID 17293) +-- TOC entry 2603 (class 2620 OID 17293) -- Name: view_projects edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1649,7 +1636,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON view_projects FOR EACH ROW EXECU -- --- TOC entry 2559 (class 2620 OID 17294) +-- TOC entry 2606 (class 2620 OID 17294) -- Name: view_users edit_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1657,7 +1644,7 @@ CREATE TRIGGER edit_permission BEFORE UPDATE ON view_users FOR EACH ROW EXECUTE -- --- TOC entry 2525 (class 2620 OID 16928) +-- TOC entry 2572 (class 2620 OID 16928) -- Name: create_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1665,7 +1652,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON create_users FOR EACH ROW EXECU -- --- TOC entry 2545 (class 2620 OID 17282) +-- TOC entry 2592 (class 2620 OID 17282) -- Name: create_project grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1673,7 +1660,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON create_project FOR EACH ROW EXE -- --- TOC entry 2549 (class 2620 OID 17285) +-- TOC entry 2596 (class 2620 OID 17285) -- Name: edit_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1681,7 +1668,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON edit_users FOR EACH ROW EXECUTE -- --- TOC entry 2553 (class 2620 OID 17289) +-- TOC entry 2600 (class 2620 OID 17289) -- Name: remove_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1689,7 +1676,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON remove_users FOR EACH ROW EXECU -- --- TOC entry 2557 (class 2620 OID 17291) +-- TOC entry 2604 (class 2620 OID 17291) -- Name: view_projects grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1697,7 +1684,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON view_projects FOR EACH ROW EXEC -- --- TOC entry 2561 (class 2620 OID 17295) +-- TOC entry 2608 (class 2620 OID 17295) -- Name: view_users grant_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1705,7 +1692,7 @@ CREATE TRIGGER grant_permission BEFORE INSERT ON view_users FOR EACH ROW EXECUTE -- --- TOC entry 2546 (class 2620 OID 17580) +-- TOC entry 2593 (class 2620 OID 17580) -- Name: create_project insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1713,7 +1700,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON create_project FOR EACH ROW EXE -- --- TOC entry 2526 (class 2620 OID 17581) +-- TOC entry 2573 (class 2620 OID 17581) -- Name: create_users insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1721,7 +1708,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON create_users FOR EACH ROW EXECU -- --- TOC entry 2550 (class 2620 OID 17582) +-- TOC entry 2597 (class 2620 OID 17582) -- Name: edit_users insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1729,7 +1716,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON edit_users FOR EACH ROW EXECUTE -- --- TOC entry 2558 (class 2620 OID 17584) +-- TOC entry 2605 (class 2620 OID 17584) -- Name: view_projects insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1737,7 +1724,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON view_projects FOR EACH ROW EXEC -- --- TOC entry 2562 (class 2620 OID 17585) +-- TOC entry 2609 (class 2620 OID 17585) -- Name: view_users insert_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1745,7 +1732,7 @@ CREATE TRIGGER insert_permission AFTER INSERT ON view_users FOR EACH ROW EXECUTE -- --- TOC entry 2524 (class 2620 OID 16915) +-- TOC entry 2571 (class 2620 OID 16915) -- Name: create_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1753,7 +1740,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON create_users FOR EACH ROW EXEC -- --- TOC entry 2544 (class 2620 OID 17283) +-- TOC entry 2591 (class 2620 OID 17283) -- Name: create_project remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1761,7 +1748,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON create_project FOR EACH ROW EX -- --- TOC entry 2547 (class 2620 OID 17286) +-- TOC entry 2594 (class 2620 OID 17286) -- Name: edit_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1769,7 +1756,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON edit_users FOR EACH ROW EXECUT -- --- TOC entry 2551 (class 2620 OID 17288) +-- TOC entry 2598 (class 2620 OID 17288) -- Name: remove_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1777,7 +1764,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON remove_users FOR EACH ROW EXEC -- --- TOC entry 2555 (class 2620 OID 17292) +-- TOC entry 2602 (class 2620 OID 17292) -- Name: view_projects remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1785,7 +1772,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON view_projects FOR EACH ROW EXE -- --- TOC entry 2560 (class 2620 OID 17296) +-- TOC entry 2607 (class 2620 OID 17296) -- Name: view_users remove_permission; Type: TRIGGER; Schema: user_permissions; Owner: joshlee -- @@ -1795,7 +1782,7 @@ CREATE TRIGGER remove_permission BEFORE DELETE ON view_users FOR EACH ROW EXECUT SET search_path = project_permissions, pg_catalog; -- --- TOC entry 2484 (class 2606 OID 17049) +-- TOC entry 2531 (class 2606 OID 17049) -- Name: add_files add_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1804,7 +1791,7 @@ ALTER TABLE ONLY add_files -- --- TOC entry 2485 (class 2606 OID 17044) +-- TOC entry 2532 (class 2606 OID 17044) -- Name: add_files add_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1813,7 +1800,7 @@ ALTER TABLE ONLY add_files -- --- TOC entry 2486 (class 2606 OID 17039) +-- TOC entry 2533 (class 2606 OID 17039) -- Name: add_files add_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1822,7 +1809,7 @@ ALTER TABLE ONLY add_files -- --- TOC entry 2489 (class 2606 OID 17105) +-- TOC entry 2536 (class 2606 OID 17105) -- Name: edit_files edit_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1831,7 +1818,7 @@ ALTER TABLE ONLY edit_files -- --- TOC entry 2488 (class 2606 OID 17100) +-- TOC entry 2535 (class 2606 OID 17100) -- Name: edit_files edit_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1840,7 +1827,7 @@ ALTER TABLE ONLY edit_files -- --- TOC entry 2487 (class 2606 OID 17095) +-- TOC entry 2534 (class 2606 OID 17095) -- Name: edit_files edit_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1849,7 +1836,7 @@ ALTER TABLE ONLY edit_files -- --- TOC entry 2507 (class 2606 OID 17486) +-- TOC entry 2554 (class 2606 OID 17486) -- Name: project_permissions_list project_permissions_list_add_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1858,7 +1845,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2508 (class 2606 OID 17491) +-- TOC entry 2555 (class 2606 OID 17491) -- Name: project_permissions_list project_permissions_list_edit_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1867,7 +1854,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2511 (class 2606 OID 17506) +-- TOC entry 2558 (class 2606 OID 17506) -- Name: project_permissions_list project_permissions_list_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1876,7 +1863,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2509 (class 2606 OID 17496) +-- TOC entry 2556 (class 2606 OID 17496) -- Name: project_permissions_list project_permissions_list_remove_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1885,7 +1872,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2506 (class 2606 OID 17481) +-- TOC entry 2553 (class 2606 OID 17481) -- Name: project_permissions_list project_permissions_list_username _fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1894,7 +1881,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2510 (class 2606 OID 17501) +-- TOC entry 2557 (class 2606 OID 17501) -- Name: project_permissions_list project_permissions_list_view_files_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1903,7 +1890,7 @@ ALTER TABLE ONLY project_permissions_list -- --- TOC entry 2492 (class 2606 OID 17129) +-- TOC entry 2539 (class 2606 OID 17129) -- Name: remove_files remove_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1912,7 +1899,7 @@ ALTER TABLE ONLY remove_files -- --- TOC entry 2491 (class 2606 OID 17124) +-- TOC entry 2538 (class 2606 OID 17124) -- Name: remove_files remove_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1921,7 +1908,7 @@ ALTER TABLE ONLY remove_files -- --- TOC entry 2490 (class 2606 OID 17119) +-- TOC entry 2537 (class 2606 OID 17119) -- Name: remove_files remove_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1930,7 +1917,7 @@ ALTER TABLE ONLY remove_files -- --- TOC entry 2495 (class 2606 OID 17177) +-- TOC entry 2542 (class 2606 OID 17177) -- Name: view_files view_files_granted_by_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1939,7 +1926,7 @@ ALTER TABLE ONLY view_files -- --- TOC entry 2494 (class 2606 OID 17172) +-- TOC entry 2541 (class 2606 OID 17172) -- Name: view_files view_files_project_name_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1948,7 +1935,7 @@ ALTER TABLE ONLY view_files -- --- TOC entry 2493 (class 2606 OID 17167) +-- TOC entry 2540 (class 2606 OID 17167) -- Name: view_files view_files_username_fkey; Type: FK CONSTRAINT; Schema: project_permissions; Owner: joshlee -- @@ -1959,7 +1946,7 @@ ALTER TABLE ONLY view_files SET search_path = public, pg_catalog; -- --- TOC entry 2483 (class 2606 OID 17013) +-- TOC entry 2529 (class 2606 OID 17013) -- Name: dirent dirent_project_name_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee -- @@ -1968,34 +1955,34 @@ ALTER TABLE ONLY dirent -- --- TOC entry 2482 (class 2606 OID 16988) +-- TOC entry 2530 (class 2606 OID 17673) -- Name: dirent dirent_super_folder_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee -- ALTER TABLE ONLY dirent - ADD CONSTRAINT dirent_super_folder_fkey FOREIGN KEY (super_folder) REFERENCES folder(object_id) ON UPDATE CASCADE ON DELETE CASCADE; + ADD CONSTRAINT dirent_super_folder_fkey FOREIGN KEY (super_folder) REFERENCES folder("UUID") ON UPDATE CASCADE ON DELETE CASCADE; -- --- TOC entry 2477 (class 2606 OID 16983) --- Name: folder folder_object_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee +-- TOC entry 2524 (class 2606 OID 17668) +-- Name: folder folder_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee -- ALTER TABLE ONLY folder - ADD CONSTRAINT folder_object_id_fkey FOREIGN KEY (object_id) REFERENCES dirent(object_id) ON UPDATE CASCADE ON DELETE CASCADE; + ADD CONSTRAINT folder_uuid_fkey FOREIGN KEY ("UUID") REFERENCES dirent("UUID") ON UPDATE CASCADE ON DELETE CASCADE; -- --- TOC entry 2478 (class 2606 OID 16993) --- Name: image image_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee +-- TOC entry 2525 (class 2606 OID 17678) +-- Name: image image_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee -- ALTER TABLE ONLY image - ADD CONSTRAINT image_file_id_fkey FOREIGN KEY (object_id) REFERENCES dirent(object_id) ON UPDATE CASCADE ON DELETE CASCADE; + ADD CONSTRAINT image_uuid_fkey FOREIGN KEY ("UUID") REFERENCES dirent("UUID") ON UPDATE CASCADE ON DELETE CASCADE; -- --- TOC entry 2476 (class 2606 OID 16777) +-- TOC entry 2523 (class 2606 OID 16777) -- Name: project project_owner _fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee -- @@ -2004,18 +1991,18 @@ ALTER TABLE ONLY project -- --- TOC entry 2479 (class 2606 OID 16998) --- Name: text text_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee +-- TOC entry 2526 (class 2606 OID 17687) +-- Name: text text_UUID_fkey; Type: FK CONSTRAINT; Schema: public; Owner: joshlee -- ALTER TABLE ONLY text - ADD CONSTRAINT text_file_id_fkey FOREIGN KEY (object_id) REFERENCES dirent(object_id) ON UPDATE CASCADE ON DELETE CASCADE; + ADD CONSTRAINT "text_UUID_fkey" FOREIGN KEY ("UUID") REFERENCES dirent("UUID") ON UPDATE CASCADE ON DELETE CASCADE; SET search_path = user_permissions, pg_catalog; -- --- TOC entry 2496 (class 2606 OID 17196) +-- TOC entry 2543 (class 2606 OID 17196) -- Name: create_project create_project_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2024,7 +2011,7 @@ ALTER TABLE ONLY create_project -- --- TOC entry 2497 (class 2606 OID 17191) +-- TOC entry 2544 (class 2606 OID 17191) -- Name: create_project create_project_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2033,7 +2020,7 @@ ALTER TABLE ONLY create_project -- --- TOC entry 2481 (class 2606 OID 17008) +-- TOC entry 2528 (class 2606 OID 17008) -- Name: create_users create_user_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2042,7 +2029,7 @@ ALTER TABLE ONLY create_users -- --- TOC entry 2480 (class 2606 OID 16931) +-- TOC entry 2527 (class 2606 OID 16931) -- Name: create_users create_user_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2051,7 +2038,7 @@ ALTER TABLE ONLY create_users -- --- TOC entry 2499 (class 2606 OID 17215) +-- TOC entry 2546 (class 2606 OID 17215) -- Name: edit_users edit_user_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2060,7 +2047,7 @@ ALTER TABLE ONLY edit_users -- --- TOC entry 2501 (class 2606 OID 17259) +-- TOC entry 2548 (class 2606 OID 17259) -- Name: remove_users remove_users_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2069,7 +2056,7 @@ ALTER TABLE ONLY remove_users -- --- TOC entry 2500 (class 2606 OID 17228) +-- TOC entry 2547 (class 2606 OID 17228) -- Name: remove_users remove_users_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2078,7 +2065,7 @@ ALTER TABLE ONLY remove_users -- --- TOC entry 2498 (class 2606 OID 17209) +-- TOC entry 2545 (class 2606 OID 17209) -- Name: edit_users untitled_table_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2087,7 +2074,7 @@ ALTER TABLE ONLY edit_users -- --- TOC entry 2513 (class 2606 OID 17546) +-- TOC entry 2560 (class 2606 OID 17546) -- Name: user_permissions_list user_permissions_list_create_project_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2096,7 +2083,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2514 (class 2606 OID 17551) +-- TOC entry 2561 (class 2606 OID 17551) -- Name: user_permissions_list user_permissions_list_create_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2105,7 +2092,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2515 (class 2606 OID 17556) +-- TOC entry 2562 (class 2606 OID 17556) -- Name: user_permissions_list user_permissions_list_edit_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2114,7 +2101,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2516 (class 2606 OID 17561) +-- TOC entry 2563 (class 2606 OID 17561) -- Name: user_permissions_list user_permissions_list_remove_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2123,7 +2110,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2512 (class 2606 OID 17541) +-- TOC entry 2559 (class 2606 OID 17541) -- Name: user_permissions_list user_permissions_list_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2132,7 +2119,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2517 (class 2606 OID 17566) +-- TOC entry 2564 (class 2606 OID 17566) -- Name: user_permissions_list user_permissions_list_view_projects_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2141,7 +2128,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2518 (class 2606 OID 17571) +-- TOC entry 2565 (class 2606 OID 17571) -- Name: user_permissions_list user_permissions_list_view_users_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2150,7 +2137,7 @@ ALTER TABLE ONLY user_permissions_list -- --- TOC entry 2503 (class 2606 OID 17264) +-- TOC entry 2550 (class 2606 OID 17264) -- Name: view_projects view_projects_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2159,7 +2146,7 @@ ALTER TABLE ONLY view_projects -- --- TOC entry 2502 (class 2606 OID 17241) +-- TOC entry 2549 (class 2606 OID 17241) -- Name: view_projects view_projects_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2168,7 +2155,7 @@ ALTER TABLE ONLY view_projects -- --- TOC entry 2505 (class 2606 OID 17269) +-- TOC entry 2552 (class 2606 OID 17269) -- Name: view_users view_users_granted_by_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2177,7 +2164,7 @@ ALTER TABLE ONLY view_users -- --- TOC entry 2504 (class 2606 OID 17254) +-- TOC entry 2551 (class 2606 OID 17254) -- Name: view_users view_users_username_fkey; Type: FK CONSTRAINT; Schema: user_permissions; Owner: joshlee -- @@ -2186,8 +2173,8 @@ ALTER TABLE ONLY view_users -- --- TOC entry 2724 (class 0 OID 0) --- Dependencies: 9 +-- TOC entry 2773 (class 0 OID 0) +-- Dependencies: 10 -- Name: project_permissions; Type: ACL; Schema: -; Owner: joshlee -- @@ -2195,177 +2182,26 @@ GRANT USAGE ON SCHEMA project_permissions TO find_user; -- --- TOC entry 2726 (class 0 OID 0) --- Dependencies: 7 +-- TOC entry 2775 (class 0 OID 0) +-- Dependencies: 8 -- Name: user_permissions; Type: ACL; Schema: -; Owner: joshlee -- -GRANT USAGE ON SCHEMA user_permissions TO add_user; -GRANT USAGE ON SCHEMA user_permissions TO edit_user; -GRANT USAGE ON SCHEMA user_permissions TO view_project; -GRANT USAGE ON SCHEMA user_permissions TO view_user; -GRANT USAGE ON SCHEMA user_permissions TO delete_user; -GRANT USAGE ON SCHEMA user_permissions TO login_user; -GRANT USAGE ON SCHEMA user_permissions TO check_permission; GRANT USAGE ON SCHEMA user_permissions TO find_user; SET search_path = project_permissions, pg_catalog; -- --- TOC entry 2728 (class 0 OID 0) --- Dependencies: 211 +-- TOC entry 2778 (class 0 OID 0) +-- Dependencies: 210 -- Name: add_files; Type: ACL; Schema: project_permissions; Owner: joshlee -- -GRANT SELECT ON TABLE add_files TO check_permission; GRANT SELECT ON TABLE add_files TO find_user; --- --- TOC entry 2729 (class 0 OID 0) --- Dependencies: 212 --- Name: edit_files; Type: ACL; Schema: project_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE edit_files TO check_permission; - - --- --- TOC entry 2730 (class 0 OID 0) --- Dependencies: 214 --- Name: view_files; Type: ACL; Schema: project_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE view_files TO check_permission; - - -SET search_path = public, pg_catalog; - --- --- TOC entry 2731 (class 0 OID 0) --- Dependencies: 200 --- Name: folder; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT INSERT ON TABLE folder TO add_file; - - --- --- TOC entry 2733 (class 0 OID 0) --- Dependencies: 210 --- Name: dirent; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT SELECT,INSERT ON TABLE dirent TO add_file; - - --- --- TOC entry 2735 (class 0 OID 0) --- Dependencies: 209 --- Name: dirent_object_id_seq; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT SELECT,USAGE ON SEQUENCE dirent_object_id_seq TO add_file; - - --- --- TOC entry 2736 (class 0 OID 0) --- Dependencies: 201 --- Name: image; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT ALL ON TABLE image TO add_file; - - --- --- TOC entry 2737 (class 0 OID 0) --- Dependencies: 198 --- Name: project; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT INSERT ON TABLE project TO create_project; -GRANT SELECT ON TABLE project TO view_project; - - --- --- TOC entry 2738 (class 0 OID 0) --- Dependencies: 202 --- Name: text; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT INSERT ON TABLE text TO add_file; - - --- --- TOC entry 2739 (class 0 OID 0) --- Dependencies: 203 --- Name: user; Type: ACL; Schema: public; Owner: joshlee --- - -GRANT INSERT ON TABLE "user" TO add_user; -GRANT SELECT ON TABLE "user" TO view_user; -GRANT SELECT,DELETE ON TABLE "user" TO delete_user; -GRANT SELECT ON TABLE "user" TO login_user; - - -SET search_path = user_permissions, pg_catalog; - --- --- TOC entry 2740 (class 0 OID 0) --- Dependencies: 215 --- Name: create_project; Type: ACL; Schema: user_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE create_project TO check_permission; - - --- --- TOC entry 2741 (class 0 OID 0) --- Dependencies: 206 --- Name: create_users; Type: ACL; Schema: user_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE create_users TO check_permission; - - --- --- TOC entry 2742 (class 0 OID 0) --- Dependencies: 216 --- Name: edit_users; Type: ACL; Schema: user_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE edit_users TO check_permission; - - --- --- TOC entry 2743 (class 0 OID 0) --- Dependencies: 217 --- Name: remove_users; Type: ACL; Schema: user_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE remove_users TO check_permission; - - --- --- TOC entry 2744 (class 0 OID 0) --- Dependencies: 218 --- Name: view_projects; Type: ACL; Schema: user_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE view_projects TO check_permission; - - --- --- TOC entry 2745 (class 0 OID 0) --- Dependencies: 219 --- Name: view_users; Type: ACL; Schema: user_permissions; Owner: joshlee --- - -GRANT SELECT ON TABLE view_users TO check_permission; - - --- Completed on 2018-02-07 00:18:25 GMT +-- Completed on 2018-02-07 18:20:05 GMT -- -- PostgreSQL database dump complete diff --git a/src/db/initPostgresDB.ts b/src/db/initPostgresDB.ts index 1bb1d77..eb979f4 100644 --- a/src/db/initPostgresDB.ts +++ b/src/db/initPostgresDB.ts @@ -1,14 +1,15 @@ -var Sequelize = require('sequelize'); -const Op = Sequelize.Op; -const gres = new Sequelize('postgres://admin:eprprJacR0hBpmWvs5IDJZTnjRAY2gM3tSm0b1af@localhost:5432/be4', - {operatorsAliases : false}); +import * as Sequelize from 'sequelize'; +const gres: Sequelize.Sequelize = new Sequelize( + 'postgres://admin:eprprJacR0hBpmWvs5IDJZTnjRAY2gM3tSm0b1af@localhost:5432/be4', + { + operatorsAliases : false + } +); - -gres - .authenticate() - .then(() => { - console.log('Connection has been established successfully.'); - }) - .catch(err => { - console.error('Unable to connect to the database:', err); - }); +gres.authenticate() + .then(() => { + // Connection has been established successfully. + }) + .catch((err: Error) => { + // Unable to connect to the database. + }); diff --git a/src/db/model/ContributorGroup.ts b/src/db/model/ContributorGroup.ts index 0fe859d..6bbcf4a 100644 --- a/src/db/model/ContributorGroup.ts +++ b/src/db/model/ContributorGroup.ts @@ -1,51 +1,54 @@ -import {Table, Model, Column, AllowNull, HasMany} from 'sequelize-typescript'; +import { AllowNull, Column, DataType, HasMany, Model, Table + } from 'sequelize-typescript'; import { default as UserJoinsProject } from './UserJoinsProject'; @Table export default class ContributorGroup extends Model<ContributorGroup> { - @AllowNull - @Column - name: string; + @AllowNull + @Column(DataType.TEXT) + public name: string | null = null; - // "Error: Foreign key for "ContributorGroup" is missing on "UserJoinsProject"." - @HasMany(() => UserJoinsProject, 'contributorGroupId') - uses: UserJoinsProject[]; + /* "Error: Foreign key for "ContributorGroup" + * is missing on "UserJoinsProject"." */ + @HasMany(() => UserJoinsProject, 'contributorGroupId') + public uses: UserJoinsProject[] = []; - @Column - canCreateFiles: boolean; + @Column + public canCreateFiles: boolean = false; - @Column - canDeleteFiles: boolean; + @Column + public canDeleteFiles: boolean = false; - @Column - canViewFiles: boolean; + @Column + public canViewFiles: boolean = false; - @Column - canAddUsers: boolean; + @Column + public canAddUsers: boolean = false; - @Column - canRemoveUsers: boolean; + @Column + public canRemoveUsers: boolean = false; - @Column - canEditUserPermissions: boolean; + @Column + public canEditUserPermissions: boolean = false; - @Column - description: string; + @AllowNull + @Column(DataType.TEXT) + public description: string | null = null; - @Column - isInternal: boolean; + @Column + public isInternal: boolean = true; - getGroupFullInfo(): GroupFullInfo { - return { - role: this.name, - description: this.description, - internal: this.isInternal - }; - } + public getContributorGroupFullInfo(): ContributorGroupFullInfo { + return { + role: `${this.name}`, + description: `${this.description}`, + internal: this.isInternal + }; + } } -type GroupFullInfo = { - role: string, - description: string, - internal: boolean -}; +export interface ContributorGroupFullInfo { + role: string; + description: string; + internal: boolean; +} diff --git a/src/db/model/File.ts b/src/db/model/File.ts index 09323e2..225512d 100644 --- a/src/db/model/File.ts +++ b/src/db/model/File.ts @@ -1,47 +1,47 @@ -import {Table, Model, Column, Unique, PrimaryKey, ForeignKey, AllowNull, - HasMany, BelongsTo, CreatedAt, UpdatedAt, HasOne} from 'sequelize-typescript'; -import { default as User } from './User'; import { default as Project } from './Project'; +import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, + HasOne, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript'; +import { default as User } from './User'; @Table export default class File extends Model<File> { - @Column - name: string; + @Column + public name: string = ''; + + @PrimaryKey + @Column + public uuid: string = ''; - @PrimaryKey - @Column - uuid: string; + @Column + public mimetype: string = ''; - @Column - mimetype: string; + @ForeignKey(() => File) + @AllowNull + @Column(DataType.TEXT) + public parentFolderId: string | null = null; - @ForeignKey(() => File) - @AllowNull - @Column - parentFolderId: string; + @BelongsTo(() => File) + public parentFolder: File = new File(); - @BelongsTo(() => File) - parentFolder: File; + @HasMany(() => File) + public containedFiles: File[] = []; - @HasMany(() => File) - containedFiles: File[]; + @ForeignKey(() => User) + @AllowNull + @Column(DataType.TEXT) + public creatorName: string | null = null; - @ForeignKey(() => User) - @AllowNull - @Column - creatorName: string; + @BelongsTo(() => User) + public creator: User = new User(); - @BelongsTo(() => User) - creator: User; - - @HasOne(() => Project) - rootFolderOf: Project; + @HasOne(() => Project) + public rootFolderOf: Project = new Project(); - @CreatedAt - @Column - uploadDate: Date; + @CreatedAt + @Column + public uploadDate: Date = new Date(); - @UpdatedAt - @Column - modifyDate: Date; + @UpdatedAt + @Column + public modifyDate: Date = new Date(); } diff --git a/src/db/model/Project.ts b/src/db/model/Project.ts index 7128296..2c26a04 100644 --- a/src/db/model/Project.ts +++ b/src/db/model/Project.ts @@ -1,72 +1,75 @@ -import {Table, Model, Column, PrimaryKey, BelongsToMany, - ForeignKey, BelongsTo, CreatedAt, UpdatedAt} from 'sequelize-typescript'; +import { default as ContributorGroup } from './ContributorGroup'; +import { default as File } from './File'; +import { BelongsTo, BelongsToMany, Column, CreatedAt, ForeignKey, + Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript'; import { default as User } from './User'; import { default as UserJoinsProject } from './UserJoinsProject'; -import { default as File } from './File'; @Table export default class Project extends Model<Project> { - @PrimaryKey - @Column - name: string; + @PrimaryKey + @Column + public name: string = ''; - @BelongsToMany(() => User, () => UserJoinsProject) - contributors: User[]; + @BelongsToMany(() => User, () => UserJoinsProject) + public contributors: User[] = []; - @ForeignKey(() => File) - @Column - rootFolderId: string; + @ForeignKey(() => File) + @Column + public rootFolderId: string = ''; - @BelongsTo(() => File) - rootFolder: File; + @BelongsTo(() => File) + public rootFolder: File = new File(); - @CreatedAt - @Column - creationDate: Date; + @CreatedAt + @Column + public creationDate: Date = new Date(); - @UpdatedAt - @Column - lastActivity: Date; + @UpdatedAt + @Column + public lastActivity: Date = new Date(); - getAccessLevel(arg0: any): any { - return "unimplemented, Will be db query on UserJoinsProject table"; - } + public getAccessLevel(user: User): ContributorGroup { + throw new Error(`unimplemented, ${this}`); + } - getUserInfo(user: User): UserInfo { - return { - username: user.username, - access_level: this.getAccessLevel(user) - } - } + public getUserInfo(user: User): UserInfo { + return { + username: user.username, + access_level: this.getAccessLevel(user) + .toString() + }; + } - getProjectFullInfo(): ProjectFullInfo { - return { - project_name: this.name, - users: this.contributors.map<UserInfo>( - (u: User) => this.getUserInfo(u) - ), - public_metadata: { - creation_date: this.creationDate - }, - //TODO: Check if we have anything to use these for yet? - private_metadata: {}, - admin_metadata: {} - }; - } + public getProjectFullInfo(): ProjectFullInfo { + return { + project_name: this.name, + users: this.contributors + .map<UserInfo>( + (u: User) => this.getUserInfo(u) + ), + public_metadata: { + creation_date: this.creationDate + }, + // TODO: Check if we have anything to use these for yet? + private_metadata: {}, + admin_metadata: {} + }; + } } -type metadata = {}; +interface Metadata {} -type UserInfo = { - username: string, - access_level: string -}; +interface UserInfo { + username: string; + access_level: string; +} -type ProjectFullInfo = { - project_name: string, - users: UserInfo[], - public_metadata: metadata, - private_metadata?: metadata, - admin_metadata?: metadata -}; +export interface ProjectFullInfo { + project_name: string; + users: UserInfo[]; + public_metadata: Metadata; + private_metadata?: Metadata; + admin_metadata?: Metadata; +} diff --git a/src/db/model/User.ts b/src/db/model/User.ts index c677fcd..5a9af07 100644 --- a/src/db/model/User.ts +++ b/src/db/model/User.ts @@ -1,80 +1,78 @@ -import {Table, Model, Column, PrimaryKey, ForeignKey, BelongsTo, - BelongsToMany, HasMany, CreatedAt} from 'sequelize-typescript'; -import { default as UserGroup } from './UserGroup'; +import { default as File } from './File'; import { default as Project } from './Project'; +import { BelongsTo, BelongsToMany, Column, CreatedAt, ForeignKey, HasMany, + Model, PrimaryKey, Table } from 'sequelize-typescript'; +import { default as UserGroup } from './UserGroup'; import { default as UserJoinsProject } from './UserJoinsProject'; -import { default as File } from './File'; - @Table export default class User extends Model<User> { - @PrimaryKey - @Column - username: string; + @PrimaryKey + @Column + public username: string = ''; - @Column - password: string; + @Column + public password: string = ''; - @ForeignKey(() => UserGroup) - @Column - userGroupId: number; + @ForeignKey(() => UserGroup) + @Column + public userGroupId: number = 0; - @BelongsTo(() => UserGroup) - userGroup: UserGroup; + @BelongsTo(() => UserGroup) + public userGroup: UserGroup = new UserGroup(); - @BelongsToMany(() => Project, () => UserJoinsProject) - projects: Project[]; + @BelongsToMany(() => Project, () => UserJoinsProject) + public projects: Project[] = []; - @HasMany(() => File) - createdFiles: File[]; + @HasMany(() => File) + public createdFiles: File[] = []; - @CreatedAt - @Column - creationDate: Date; + @CreatedAt + @Column + public creationDate: Date = new Date(); - //TODO implement - getAccessLevel(project: Project): string { - return "null"; - } + // TODO implement + public getAccessLevel(project: Project): string { + throw new Error(`unimplemented, ${this}`); + } - getProjectInfo(project: Project): ProjectInfo { - return { - project_name: project.name, - access_level: this.getAccessLevel(project) - }; - } + public getProjectInfo(project: Project): ProjectInfo { + return { + project_name: project.name, + access_level: this.getAccessLevel(project) + }; + } - getUserFullInfo() : UserFullInfo { - console.log(this); - return { - username : this.username, - privileges: [this.userGroup.name], - projects : this.projects.map<ProjectInfo>( - (p: Project) => this.getProjectInfo(p) - ), - //TODO: Check if we have anything to use these for yet? - public_user_metadata: {}, - private_user_metadata: {}, - public_admin_metadata: {}, - private_admin_metadata: {} - }; - } + public getUserFullInfo(): UserFullInfo { + return { + username : this.username, + privileges: [`${this.userGroup.name}`], + projects : this.projects.map<ProjectInfo>( + (p: Project) => this.getProjectInfo(p) + ), + // TODO: Check if we have anything to use these for yet? + public_user_metadata: {}, + private_user_metadata: {}, + public_admin_metadata: {}, + private_admin_metadata: {} + }; + } } -//TODO MAKE PRETTY below -type metadata = {}; +// TODO MAKE PRETTY below +interface Metadata {} -type ProjectInfo = { - project_name: string, - access_level: string -}; +interface ProjectInfo { + project_name: string; + access_level: string; +} -type UserFullInfo = { - username: string, - privileges: string[], - projects: ProjectInfo[], - public_user_metadata: metadata, - private_user_metadata: metadata, - public_admin_metadata: metadata, - private_admin_metadata: metadata -}; +export interface UserFullInfo { + username: string; + privileges: string[]; + projects: ProjectInfo[]; + public_user_metadata: Metadata; + private_user_metadata: Metadata; + public_admin_metadata: Metadata; + private_admin_metadata: Metadata; +} diff --git a/src/db/model/UserGroup.ts b/src/db/model/UserGroup.ts index 35eb33d..865fbbc 100644 --- a/src/db/model/UserGroup.ts +++ b/src/db/model/UserGroup.ts @@ -1,49 +1,52 @@ -import {Table, Model, Column, HasMany} from 'sequelize-typescript'; +import { AllowNull, Column, DataType, HasMany, Model, Table + } from 'sequelize-typescript'; import { default as User } from './User'; -type UserPrivilege = { - privilege: string, - description: string, - internal: boolean +interface UserPrivilege { + privilege: string; + description: string; + internal: boolean; } @Table export default class UserGroup extends Model<UserGroup> { - @Column - name: string; + @AllowNull + @Column(DataType.TEXT) + public name: string | null = null; - @HasMany(() => User) - users: User[]; + @HasMany(() => User) + public users: User[] = []; - @Column - canCreateUsers: boolean; + @Column + public canCreateUsers: boolean = false; - @Column - canDeleteUsers: boolean; + @Column + public canDeleteUsers: boolean = false; - @Column - canEditUsers: boolean; + @Column + public canEditUsers: boolean = false; - @Column - canCreateProjects: boolean; + @Column + public canCreateProjects: boolean = false; - @Column - canDeleteProjects: boolean; + @Column + public canDeleteProjects: boolean = false; - @Column - canEditProjects: boolean; + @Column + public canEditProjects: boolean = false; - @Column - isInternal: boolean + @Column + public isInternal: boolean = true; - @Column - description: string; + @AllowNull + @Column(DataType.TEXT) + public description: string | null = null; - getPrivelege() : UserPrivilege { - return { - privilege : this.name, - description : this.description, - internal : this.isInternal - } - } + public getPrivelege(): UserPrivilege { + return { + privilege : `${this.name}`, + description : `${this.description}`, + internal : this.isInternal + }; + } } diff --git a/src/db/model/UserJoinsProject.ts b/src/db/model/UserJoinsProject.ts index 230e1dd..36a1591 100644 --- a/src/db/model/UserJoinsProject.ts +++ b/src/db/model/UserJoinsProject.ts @@ -1,26 +1,27 @@ -import {Table, Model, Column, ForeignKey, CreatedAt, BelongsTo} from 'sequelize-typescript'; -import { default as User } from './User'; import { default as Project } from './Project'; +import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table + } from 'sequelize-typescript'; +import { default as User } from './User'; import { default as ContributorGroup } from './UserGroup'; @Table export default class UserJoinsProject extends Model<UserJoinsProject> { - @ForeignKey(() => User) - @Column - username: string; + @ForeignKey(() => User) + @Column + public username: string = ''; - @ForeignKey(() => Project) - @Column - projectName: string; + @ForeignKey(() => Project) + @Column + public projectName: string = ''; - @CreatedAt - @Column - joinDate: Date; + @CreatedAt + @Column + public joinDate: Date = new Date(); - @ForeignKey(() => ContributorGroup) - @Column - contributorGroupId: number; + @ForeignKey(() => ContributorGroup) + @Column + public contributorGroupId: number = 0; - @BelongsTo(() => ContributorGroup) - contributorGroup: ContributorGroup; + @BelongsTo(() => ContributorGroup) + public contributorGroup: ContributorGroup = new ContributorGroup(); } diff --git a/src/db/orm.ts b/src/db/orm.ts index 02ae74b..01d8037 100644 --- a/src/db/orm.ts +++ b/src/db/orm.ts @@ -1,12 +1,12 @@ import { Sequelize } from 'sequelize-typescript'; -const seq = new Sequelize({ +const seq: Sequelize = new Sequelize({ database: 'be4', dialect: 'postgres', username: 'admin', password: '', operatorsAliases: false, - modelPaths: [__dirname + '/model'] + modelPaths: [`${__dirname}/model`] }); export default seq; diff --git a/src/index.ts b/src/index.ts index 5e8a9d0..06989ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,49 +1,54 @@ -import { default as seq } from './db/orm'; +/* tslint:disable:no-console + * This only goes here until we have a logging system */ + +console.log('begin import'); import { default as app } from './app'; +import { default as seq } from './db/orm'; +console.log('end import'); -import { default as User } from './db/model/UserGroup'; import { default as UserGroup } from './db/model/UserGroup'; -// use default port 3000 or port supplied by OS -const port: number = process.env.PORT || 3000; - -(async () => { - console.log('Booting PSQL database'); - - await seq.authenticate(); - - console.log('Resetting Database'); - - await seq.sync({ - force: true - }); - - let admin: UserGroup = new UserGroup({ - name: 'admin', - canCreateUsers: true, - canDeleteUsers: true, - canEditUsers: true, - canCreateProjects: true, - canDeleteProjects: true, - canEditProjects: true, - isInternal: false, - description: 'Systems admin' - }); - admin.save(); - - // let user: User = new User({ - // username: 'Tom', - // password: 'woa' - // }); - // user.save(); - - console.log('Booting ExpressJS server'); - - app.listen(port, (err) => { - if (err) { - return console.log(err); - } else { - return console.log(`server is listening on port ${port}`); - } - }); +const DEFAULT_PORT: number = 3000; + +// Use default port 3000 or port supplied by OS +const port: number = process.env.PORT + ? process.env.PORT + : DEFAULT_PORT; + +// tslint:disable:no-floating-promises +(async(): Promise<void> => { + console.log('Booting PSQL database'); + + await seq.authenticate(); + + console.log('Resetting Database'); + + await seq.sync({ + force: true + }); + + const admin: UserGroup = new UserGroup({ + name: 'admin', + canCreateUsers: true, + canDeleteUsers: true, + canEditUsers: true, + canCreateProjects: true, + canDeleteProjects: true, + canEditProjects: true, + isInternal: false, + description: 'Systems admin' + }); + + // tslint:disable:no-floating-promises + admin.save(); + + console.log('Booting ExpressJS server'); + + app.listen(port, (err: Error) => { + if (err) { + return console.log(err); + } else { + return console.log(`server is listening on port ${port}`); + } + }); })(); diff --git a/src/matcher/options.test.ts b/src/matcher/options.test.ts index 39c4b3e..ff5763e 100644 --- a/src/matcher/options.test.ts +++ b/src/matcher/options.test.ts @@ -1,105 +1,163 @@ -import * as mocha from 'mocha'; -import chai = require('chai'); -var should = chai.should(); +/* tslint:disable:typedef */ +// Disabled to allow quick template creation. + +/* tslint:disable:newline-per-chained-call */ +// Disabled to allow Chai- and Mocha-style test formatting. + +/* tslint:disable:no-unused-expression */ +// Disabled to allow `...to.be.true`. + +import * as chai from 'chai'; +chai.should(); import * as options from './options'; import { default as types } from './types'; -describe('Object Matching:', () => { - describe('Rough Matching', () => { - it('accepts basic things', () => { - let template = { - a: types.string - }; - let matchee = { - a: "yes" - }; - options.match(template, matchee).should.be.true; - }); - it('accepts objects with superfluous properties', () => { - let template = { - a: types.number - }; - let matchee = { - a: 40, - b: 20 - }; - options.match(template, matchee).should.be.true; - }); - it('rejects objects missing some properties', () => { - let template = { - a: types.boolean, - b: types.number, - c: types.number - }; - let matchee = { - b: 5 - }; - options.match(template, matchee).should.be.false; - }); - it('accepts objects that omit not_present properties', () => { - let template = { - a: types.function, - b: types.not_present, - c: types.not_present - }; - let matchee = { - a: new Function() - }; - options.match(template, matchee).should.be.true; - }); - it('rejects empty objects for non-empty templates', () => { - let template = { - a: types.boolean - }; - let matchee = { - }; - options.match(template, matchee).should.be.false; - }); - it('accepts empty objects for empty templates', () => { - let template = { - }; - let matchee = { - }; - options.match(template, matchee).should.be.true; - }); - it('accepts nested objects that match', () => { - let template = { - a: types.number, - b: { - ba: types.string, - bb: types.function - }, - c: types.boolean - }; - let matchee = { - a: 432, - b: { - ba: "baracus", - bb: new Function(), - }, - c: true, - x: false - }; - options.match(template, matchee).should.be.true; - }); - it('accepts literal matches', () => { - let template = { - a: "literal" - }; - let matchee = { - a: "literal" - }; - options.match(template, matchee).should.be.true; - }); - it('rejects incorrect literal matches', () => { - let template = { - g: 99 - }; - let matchee = { - g: 80 - }; - options.match(template, matchee).should.be.false; - }); - }); +// tslint:disable-next-line:no-require-imports + +describe('Matching:', () => { + describe('Rough Matching', () => { + context('for literals', () => { + context('accepts matching', () => { + it('strings', () => { + options.match('a', 'a').should.be.true; + }); + it('numbers', () => { + options.match(3, 3).should.be.true; + }); + it('boolean values', () => { + options.match(true, true).should.be.true; + }); + it('null to null', () => { + options.match(null, null).should.be.true; + }); + }); + context('rejects', () => { + it('different strings', () => { + options.match('x', 'y').should.be.false; + }); + it('different numbers', () => { + options.match(20, 42).should.be.false; + }); + it('different boolean values', () => { + options.match(true, false).should.be.false; + }); + it('different types', () => { + options.match('55', 55).should.be.false; + }); + it('null matched with non-null values', () => { + options.match(null, false).should.be.false; + }); + it('non-null values matched with null', () => { + options.match(0, null).should.be.false; + }); + }); + }); + context('for checker functions', () => { + context('accepts', () => { + it('values that succeed the checker function', () => { + options.match(types.number, 9).should.be.true; + }); + }); + context('rejects', () => { + it('values that do not succeed the checker function', () => { + options.match(types.boolean, 'true').should.be.false; + }); + }); + }); + it('accepts basic things', () => { + const template = { + a: types.string + }; + const matchee = { + a: 'yes' + }; + options.match(template, matchee).should.be.true; + }); + it('accepts objects with superfluous properties', () => { + const template = { + a: types.number + }; + const matchee = { + a: 40, + b: 20 + }; + options.match(template, matchee).should.be.true; + }); + it('rejects objects missing some properties', () => { + const template = { + a: types.boolean, + b: types.number, + c: types.number + }; + const matchee = { + b: 5 + }; + options.match(template, matchee).should.be.false; + }); + it('accepts objects that omit not_present properties', () => { + const template = { + a: types.number, + b: types.not_present, + c: types.not_present + }; + const matchee = { + a: 4 + }; + options.match(template, matchee).should.be.true; + }); + it('rejects empty objects for non-empty templates', () => { + const template = { + a: types.boolean + }; + const matchee = { + }; + options.match(template, matchee).should.be.false; + }); + it('accepts empty objects for empty templates', () => { + const template = { + }; + const matchee = { + }; + options.match(template, matchee).should.be.true; + }); + it('accepts nested objects that match', () => { + const template = { + a: types.number, + b: { + ba: types.string, + bb: types.string + }, + c: types.boolean + }; + const matchee = { + a: 432, + b: { + ba: 'baracus', + bb: 'ATEAM' + }, + c: true, + x: false + }; + options.match(template, matchee).should.be.true; + }); + it('accepts literal matches', () => { + const template = { + a: 'literal' + }; + const matchee = { + a: 'literal' + }; + options.match(template, matchee).should.be.true; + }); + it('rejects incorrect literal matches', () => { + const template = { + g: 99 + }; + const matchee = { + g: 80 + }; + options.match(template, matchee).should.be.false; + }); + }); }); diff --git a/src/matcher/options.ts b/src/matcher/options.ts index 9b07163..62e4985 100644 --- a/src/matcher/options.ts +++ b/src/matcher/options.ts @@ -1,86 +1,99 @@ -import { default as types } from './types'; +import { Atom, default as types } from './types'; -type matchType<T = any> - = (boolean | ((T) => boolean)); +type Checker = ((value: Value | undefined) => boolean); -export function match(template: Object, value?: Object) { - if (value === undefined) { - return match.bind(null, template); - } +export type TemplateValue = + Atom | Template | Checker; - for (let k of Object.keys(template)) { - let f; - if (types.object(template[k])) { - f = match(template[k]); - } else if (types.function(template[k])) { - f = template[k]; - } else { - f = (v) => v === template[k]; - } - - if (!f(value[k])) { - return false; - } - } - return true; +export interface Template { + [key: string]: TemplateValue | undefined; } -export function exact(template: Object, value?: Object) { - if (value === undefined) { - return exact.bind(null, template); - } - - let k1 = Object.keys(template); - let k2 = Object.keys(value); - - return match(template, value) - && k2.every((x) => k1.indexOf(x) < 0); -} +export type Value = + { [key: string]: Value | undefined } | Atom; -export function optional(template: Function, value?: any) { - if (value === undefined) { - return optional.bind(null, template); - } +const matchNoCurry: + (template: TemplateValue, value: Value | undefined) => boolean = + (template: TemplateValue, value: Value | undefined): boolean => { + if (types.atom(template)) { + return template === value; + } else if (types.function(template)) { + return template(value); + } else if (types.atom(value) || value === undefined) { + return false; + } else if (types.object(template)) { + return Object.keys(template) + .every((key: string): boolean => { + const v: Value | undefined = value[key]; + return matchNoCurry(template[key] as TemplateValue, v); + }); + } else { + throw new Error(`Unknown template value: ${template}`); + } +}; - return types.undefined(value) - || template(value); -} +// tslint:disable-next-line:typedef +export const match = (template: TemplateValue, value?: Value) => { + if (value === undefined) { + return matchNoCurry.bind(null, template); + } + return matchNoCurry(template, value); +}; -export function alternative(templates: any[], value?: any) { - if (value === undefined) { - return alternative.bind(null, templates); - } +// tslint:disable-next-line:typedef +export const exact = (template: Template, value?: Value) => { + if (value === undefined) { + return exact.bind(null, template); + } + if (!match(template, value)) { + return false; + } + if (!types.atom(value)) { + const k1: string[] = Object.keys(template); + const k2: string[] = Object.keys(value); + return k2.every((x: string) => k1.indexOf(x) < 0); + } else { + return true; + } +}; - if (templates.length === 0) { - return false; - } else { - let t = templates.map((x) => { - if (types.function(x)) { - return x; - } else if (types.object(x)) { - return match(x); - } else { - return (v) => x === v; - } - }); - return t.some((x) => x(value)); - } -} +// tslint:disable-next-line:typedef +export const optional = (template: TemplateValue, value?: Value) => { + if (value === undefined) { + return optional.bind(null, template); + } + return types.undefined(value) || match(template, value); +}; -export function array(template: Object, values?: Array<Object>) { - if (values === undefined) { - return array.bind(null, template); - } +// tslint:disable-next-line:typedef +export const alternative = (templates: TemplateValue[], value?: Value) => { + if (value === undefined) { + return alternative.bind(null, templates); + } + if (templates.length === 0) { + return false; + } else { + return templates.some((t: TemplateValue): boolean => match(t, value)); + } +}; - let m = match(template) as ((Object) => boolean); - return values.every(m); -} +// tslint:disable-next-line:typedef +export const array = (template: TemplateValue, values?: Value[]) => { + if (values === undefined) { + return array.bind(null, template); + } + const m: Checker = types.function(template) + ? template + : match.bind(null, template); + return values.every(m); +}; +// tslint:disable-next-line:typedef const options = { - match : match, - exact : exact, - optional : optional, - alternative : alternative, - array : array + match, + exact, + optional, + alternative, + array }; export default options; diff --git a/src/matcher/types.test.ts b/src/matcher/types.test.ts new file mode 100644 index 0000000..398064c --- /dev/null +++ b/src/matcher/types.test.ts @@ -0,0 +1,178 @@ +/* tslint:disable:no-unused-expression */ +// Disabled to allow `...to.be.true`. + +import * as chai from 'chai'; +chai.should(); + +import { default as types } from './types'; + +describe('Type Checking:', () => { + for (const x of [ + { name: 'Object', func: types.object }, + { name: 'Number', func: types.number }, + { name: 'Integer', func: types.integer }, + { name: 'String', func: types.string }, + { name: 'Boolean', func: types.boolean }, + { name: 'Array', func: types.array } + ]) { + describe(`${x.name} Checking`, () => { + it('rejects null', () => { + x.func(null).should.be.false; + }); + it('rejects undefined', () => { + x.func(undefined).should.be.false; + }); + }); + } + + describe('Presence Checking', () => { + it('accepts non-undefined values', () => { + types.anything(1).should.be.true; + types.anything('string').should.be.true; + types.anything(false).should.be.true; + }); + it('accepts null', () => { + types.anything(null).should.be.true; + }); + it('rejects undefined', () => { + types.anything(undefined).should.be.false; + }); + it('rejects objects without the named property', () => { + const x: { [key: string]: number } = {}; + /* There's no way to pick a key that definitely won't be + /* on the object */ + types.anything(x["hopefully this isn't a property"]) + .should.be.false; + }); + }); + + describe('Absence Checking', () => { + it('accepts undefined', () => { + types.not_present(undefined).should.be.true; + }); + }); + + describe('Number Checking', () => { + it('accepts positive integers', () => { + types.number(4).should.be.true; + }); + it('accepts negative integers', () => { + types.number(-10).should.be.true; + }); + it('accepts floats', () => { + types.number(3.14).should.be.true; + }); + it('accepts zero', () => { + types.number(0).should.be.true; + }); + it('accepts boxed numbers', () => { + // tslint:disable-next-line:no-construct + types.number(new Number(20)).should.be.true; + }); + it('rejects strings', () => { + types.number('haha').should.be.false; + }); + it('rejects objects', () => { + types.number(new Object()).should.be.false; + }); + it('rejects arrays', () => { + types.number([1, 2, 3]).should.be.false; + }); + it('rejects things that look like numbers', () => { + types.number('1234').should.be.false; + types.number('-3.14').should.be.false; + }); + it('accepts NaN', () => { + types.number(NaN).should.be.true; + }); + it('accepts Infinity', () => { + types.number(Infinity).should.be.true; + }); + }); + + describe('Integer Checking', () => { + it('rejects non-integer numbers', () => { + types.integer(3.14).should.be.false; + }); + it('rejects NaN', () => { + types.integer(NaN).should.be.false; + }); + it('rejects Infinity', () => { + types.integer(Infinity).should.be.false; + }); + }); + + describe('String Checking', () => { + it('accepts basic primitive strings', () => { + types.string('string!').should.be.true; + }); + it('accepts strings of numbers', () => { + types.string('1234').should.be.true; + }); + it('accepts the empty string', () => { + types.string('').should.be.true; + }); + it('accepts non-primitive string objects', () => { + // tslint:disable-next-line:no-construct + types.string(new String('String!')).should.be.true; + }); + it('rejects numbers', () => { + types.string(5).should.be.false; + // tslint:disable-next-line:no-construct + types.string(new Number(28)).should.be.false; + }); + it('rejects objects', () => { + types.string(new Object()).should.be.false; + }); + it('rejects arrays', () => { + types.string(['ah', 'ha']).should.be.false; + }); + }); + + describe('Boolean Checking', () => { + it('accepts true and false', () => { + types.boolean(true).should.be.true; + types.boolean(false).should.be.true; + }); + it('rejects numbers', () => { + types.boolean(2).should.be.false; + }); + it('rejects strings', () => { + types.boolean('not boolean').should.be.false; + }); + it('rejects strings of boolean values', () => { + types.boolean('true').should.be.false; + }); + it('rejects objects', () => { + types.boolean(new Object()).should.be.false; + }); + it('rejects arrays', () => { + types.boolean([true, true, false]).should.be.false; + }); + it('rejects falsy values', () => { + types.boolean(0).should.be.false; + }); + }); + + describe('Array Checking', () => { + it('accepts arrays', () => { + types.array([1, 'two', false]).should.be.true; + }); + it('accepts empty arrays', () => { + types.array([]).should.be.true; + types.array(new Array()).should.be.true; + }); + it('rejects strings', () => { + types.array('not an array').should.be.false; + }); + it('rejects strings that look like arrays', () => { + types.array('[1, 2, false]').should.be.false; + }); + it('rejects numbers', () => { + types.array(8).should.be.false; + }); + it('rejects objects', () => { + types.array(new Object()).should.be.false; + }); + }); +}); diff --git a/src/matcher/types.ts b/src/matcher/types.ts index 3870df4..aad1e9f 100644 --- a/src/matcher/types.ts +++ b/src/matcher/types.ts @@ -1,32 +1,79 @@ -function typeCheckerGenerator<T>(test: T): (v: any) => v is T { - let f = (value): value is T => - value != null && value.constructor === test.constructor; - return f; -} - -export const isObject = typeCheckerGenerator<Object>({}); -export const isNumber = typeCheckerGenerator<Number>(0); -export const isString = typeCheckerGenerator<String>(""); -export const isBoolean = typeCheckerGenerator<Boolean>(true); -export const isArray = typeCheckerGenerator<Array<any>>([]); -export const isFunction = typeCheckerGenerator<Function>(new Function()); -export const isNull = (v) => v === null; -export const isUndefined = (v) => v === undefined; -export const isPresent = (v) => !isUndefined(v); -export const isInteger = (value: any) => isNumber(value) - && Number.isInteger(value as number); - -const types = { - object: isObject, - number: isNumber, - string: isString, - boolean: isBoolean, - array: isArray, - function: isFunction, - integer: isInteger, - null: isNull, - not_present: isUndefined, - undefined: isUndefined, - anything: isPresent +/* tslint:disable:no-any */ + +type Checker<T = any> = (v: any) => v is T; + +export type Atom = Number | String | Boolean | null; + +const typeCheckerGenerator: <T>(test: T) => Checker<T> = + <T>(test: T): Checker<T> => { + const f: Checker<T> = (value: any): value is T => + value != null && value.constructor === test.constructor; + return f; +}; + +export const isObject: Checker<Object> = + typeCheckerGenerator<Object>({}); + +export const isNumber: Checker<Number> = + typeCheckerGenerator<Number>(0); + +export const isString: Checker<String> = + typeCheckerGenerator<String>(''); + +export const isBoolean: Checker<Boolean> = + typeCheckerGenerator<Boolean>(true); + +export const isArray: Checker<any[]> = + typeCheckerGenerator<any[]>([]); + +export const isFunction: Checker<Function> = + typeCheckerGenerator<Function>(new Function()); + +export const isNull: Checker<null> = + (v: any): v is null => v === null; + +export const isUndefined: Checker<undefined> = + (v: any): v is undefined => v === undefined; + +export const isPresent: (v: any) => boolean = + (v: any): boolean => !isUndefined(v); + +export const isInteger: Checker<Number> = + (v: any): v is Number => isNumber(v) && Number.isInteger(v as number); + +export const isAtom: Checker<Atom> = + (v: any): v is Atom => + isNull(v) || isNumber(v) || isString(v) || isBoolean(v); + +const types: { + object: Checker<Object>; + number: Checker<Number>; + string: Checker<String>; + boolean: Checker<Boolean>; + array: Checker<any[]>; + function: Checker<Function>; + integer: Checker<Number>; + null: Checker<null>; + present: (v: any) => boolean; + is_present: (v: any) => boolean; + not_present: Checker<undefined>; + undefined: Checker<undefined>; + anything: (v: any) => boolean; + atom: Checker<Atom>; +} = { + object: isObject, + number: isNumber, + string: isString, + boolean: isBoolean, + array: isArray, + function: isFunction, + integer: isInteger, + null: isNull, + present: isPresent, + is_present: isPresent, + not_present: isUndefined, + undefined: isUndefined, + anything: isPresent, + atom: isAtom }; export default types; diff --git a/src/serverConfig.ts b/src/serverConfig.ts index b10641a..ea7b195 100644 --- a/src/serverConfig.ts +++ b/src/serverConfig.ts @@ -1,52 +1,136 @@ -var serverConfig : Property[] = []; +const serverConfig: Property[] = []; -/* This is a class used to define the optional attribute of Property, - if the property is user configurable*/ +/** + * A way to display user-configurable properties. + */ class PropertyDisplay { - constructor(cat : string, grp : string, dn : string, desc : string) { - this.category = cat; - this.group = grp; - this.display_name = dn; - this.description = desc; - }; - category : string; - group : string; - display_name : string; - description : string; -}; + /** + * The category the property belongs to. + */ + public category: string; -/* This is a class used to contain all of the protocol attributes of a Property - of the current backend server.*/ -class Property { - id : string; - display? : PropertyDisplay; - read_only : boolean; - type : string; - value : string | number | boolean; -} + /** + * The group the property belongs to. + */ + public group: string; + + /** + * The name for the property to display to a user. + */ + public displayName: string; + + /** + * The description of the property. + */ + public description: string; -//Logging -var property_display = new PropertyDisplay("Logging", "BE4", "Is logging enabled?", "This property defines if logging is currently enabled on this backend server."); -serverConfig.push({id : "Server_Log", display : property_display, read_only : false, type : "boolean", value : false}); - -//caching settings (global) -serverConfig.push({id : "Global_Cache_Limit", read_only : true, type : "integer", value : 1}); -//caching settings (project level) -property_display = new PropertyDisplay("Caching", "BE4", "Caching Type", "This property defines the current caching style for this project."); -serverConfig.push({id : "project_example", display : property_display, read_only : false, type : "integer", value : 1}); - -function propertyExists (propKey : string): number { - var found = -1; - for (var prop in serverConfig) { - if (serverConfig[prop].id == propKey) { - found = parseInt(prop); - break; - } - } - return found; + /** + * Constructs a [[PropertyDisplay]] using its properties. + * + * @param cat The property's category. + * @param grp The property's group. + * @param dn The property's displayable name. + * @param desc A description of the property. + */ + public constructor(cat: string, grp: string, dn: string, desc: string) { + this.category = cat; + this.group = grp; + this.displayName = dn; + this.description = desc; + } } -module.exports = { - default : serverConfig, - propertyExists : propertyExists, +/** + * A server property that infuences the running of the server. + * Loaded from configs at launch, and possibly editable during run-time. + */ +export interface Property { + /** + * The property's unique ID. + */ + id: string; + + /** + * How to display the property to the user. + */ + display?: PropertyDisplay; + + /** + * Is the property read-only, or can it be edited at run-time? + */ + readOnly: boolean; + + /** + * The variable type of the property. + * + * These strings represent Javascript types directly, + * except `"integer"`, which is a `number` in logic. + */ + type: 'string' | 'number' | 'integer' | 'boolean'; + + /** + * The value of the property. + */ + value: string | number | boolean; } + +// Logging +let propertyDisplay: PropertyDisplay = new PropertyDisplay( + 'Logging', + 'BE4', + 'Is logging enabled?', + 'This property defines if logging is currently enabled on this backend server.' +); + +serverConfig.push({ + id: 'Server_Log', + display: propertyDisplay, + readOnly: false, + type: 'boolean', + value: false +}); + +// Caching Settings (global) +serverConfig.push({ + id: 'Global_Cache_Limit', + readOnly: true, + type: 'integer', + value: 1 +}); + +// Caching Settings (project level) +propertyDisplay = new PropertyDisplay( + 'Caching', + 'BE4', + 'Caching Type', + 'This property defines the current caching style for this project.' +); + +serverConfig.push({ + id: 'project_example', + display: propertyDisplay, + readOnly: false, + type: 'integer', + value: 1 +}); + +/** + * Checks if a property exists in the server's property list. + * + * @param propKey The property unique ID to search for. + * @returns The index of the property in the server's property list, + * or `-1` if the property is not present. + */ +export const propertyExists: (propKey: string) => number = + (propKey: string): number => { + let found: number = -1; + for (const prop in serverConfig) { + if (serverConfig[prop].id === propKey) { + found = parseInt(prop, 10); + break; + } + } + return found; +}; + +export default serverConfig; |
