aboutsummaryrefslogtreecommitdiff
path: root/src/FileRouter.ts
diff options
context:
space:
mode:
authorHafeez2018-04-15 18:22:09 +0100
committerHafeez2018-04-15 18:22:09 +0100
commit42e30930b635eb91bdb97d0a889081cd291f3740 (patch)
treec355a2b8083f9f69beb0d424038e3460713f8b38 /src/FileRouter.ts
parentstarted modifying file upload (diff)
parentfixed fetching current_user (diff)
downloadmedicine-42e30930b635eb91bdb97d0a889081cd291f3740.tar.gz
medicine-42e30930b635eb91bdb97d0a889081cd291f3740.zip

Merge branch ‘trh/gets’ of gitlab.cs.st-andrews.ac.uk:cs3099group-be-4/project-code into trh/gets

Diffstat (limited to 'src/FileRouter.ts')
-rw-r--r--src/FileRouter.ts34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 0a8d06a..d6cea53 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -65,6 +65,7 @@ const getProtocols: Middleware = (
const postLog: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
+ res.locals.modified = true;
logger.debug('Adding forwarded log');
if (!req.user.hasPrivilege('logging')) {
next(new RequestError(401, 'invalid_privilege'));
@@ -108,9 +109,15 @@ const getLog: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug('Fetching log');
+ res.locals.modified = true;
if (!req.user.hasPrivilege('admin')) {
next(new RequestError(401, 'invalid_privilege'));
}
+ /* tslint:disable */
+ if(!req.params.level) req.params.level = 'info';
+ if(!req.params.before) req.params.before = new Date();
+ if(!req.params.after) req.params.after = new Date(0);
+ /* tslint:enable */
res.locals.data = logger.fetch(
req.params.level, {
before: new Date(req.params.before),
@@ -165,6 +172,7 @@ const postProperties: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug('Editing server properties');
+ res.locals.modified = true;
for (const newProp of req.body) {
const prop: Property | undefined = serverConfig.find(
(p: Property): boolean => p.id === newProp.id
@@ -257,6 +265,7 @@ const getUserProperties: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug('Listing additional properties for a user');
+ res.locals.modified = true;
if (res.locals.user == null) {
next(new RequestError(404, 'user_not_found'));
return;
@@ -289,6 +298,7 @@ const getUsername: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug(`Listing user ${res.locals.user}`);
+ res.locals.modified = true;
if (res.locals.user == null) {
next(new RequestError(404, 'user_not_found'));
return;
@@ -327,6 +337,7 @@ const postCurUser: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
logger.debug('Editing current user');
+ res.locals.modified = true;
try {
await req.user.updateInfo(req.body);
await req.user.save();
@@ -357,14 +368,15 @@ const postUsername: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
let user: User | null | undefined = res.locals.user;
+ res.locals.modified = true;
if (user == null) {
- console.log('Adding new user');
+ logger.debug('Adding new user');
user = new User({
username: req.params.username,
password: req.params.password
});
} else {
- console.log('Editing user');
+ logger.debug('Editing user');
user.password = req.params.password;
}
if (req.body) {
@@ -387,6 +399,7 @@ const postUsername: Middleware = async(
const getProjectRoles: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
+ res.locals.modified = true;
logger.debug('Listing available project roles');
const roles: ContributorGroup[] = await ContributorGroup.findAll();
res.locals.data = roles.filter(
@@ -418,6 +431,7 @@ const getProjects: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
logger.debug('Listing all projects');
+ res.locals.modified = true;
const projects: Project[] = await Project.findAll({
include: [
User
@@ -425,7 +439,7 @@ const getProjects: Middleware = async(
});
res.locals.data = projects.map(
(p: Project): ProjectFullInfo => p.fullInfo
- );
+ );
next();
};
@@ -450,6 +464,7 @@ const getProjectName: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
logger.debug('Getting project properties');
+ res.locals.modified = true;
const project: Project | null = res.locals.project;
if (project == null) {
return next(new RequestError(404, 'project_not_found'));
@@ -476,6 +491,7 @@ const postProjectName: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
let project: Project | null = res.locals.project;
+ res.locals.modified = true;
let promise: PromiseLike<File> | null = null;
if (project == null) {
logger.debug('Adding new project');
@@ -505,6 +521,7 @@ const getProjectProperties: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug('Getting project properties');
+ res.locals.modified = true;
if (res.locals.project == null) {
next(new RequestError(404, 'project_not_found'));
} else {
@@ -520,6 +537,7 @@ const getFile: Middleware = async(
req: Request, res: Response, next: NextFunction
): Promise<void> => {
logger.debug(`Getting file in ${req.query.view} view`);
+ res.locals.modified = true;
const file: File | null = res.locals.file;
if (file == null) {
return next(new RequestError(404, 'file_not_found'));
@@ -547,7 +565,8 @@ const getFileId: Middleware = getFile;
const postFilePath: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
- logger.debug('Receiving file to ' + res.locals.parentFolder);
+ logger.debug(`Receiving file to ${res.locals.parentFolder}`);
+ res.locals.modified = true;
if (res.locals.file != null) {
next(new RequestError(400, 'file_exists'));
}
@@ -612,7 +631,7 @@ export class FileRouter {
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.post('/projects/:project_name/files/:path', postFilePath);
this.router.get ('/projects/:project_name/files_by_id/:id', getFileId);
}
@@ -669,7 +688,7 @@ export class FileRouter {
req: Request, res: Response, next: NextFunction,
filename: string
): Promise<void> => {
- console.log("wrong precond")
+ console.log(`parsing path ${filename}`)
logger.debug(`Searching for file ${filename}`);
const fileNames: string[] = req.params.path.split('/');
const project: Project | null = res.locals.project;
@@ -722,7 +741,7 @@ export class FileRouter {
req: Request, res: Response, next: NextFunction,
fileId: string
): Promise<void> => {
- console.log(`Searching for file ${fileId}`);
+ console.log(`parsing id ${fileId}`);
const file: File | null = await File.findOne({
include: [{all: true}],
where: {
@@ -730,7 +749,6 @@ export class FileRouter {
}
});
res.locals.file = file;
- console.log("precondition: " + file)
next();
}
);