forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(system-server): add appid to applications;
- Loading branch information
Showing
32 changed files
with
341 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* @Author: Maslow<wangfugen@126.com> | ||
* @Date: 2021-08-30 15:22:34 | ||
* @LastEditTime: 2021-09-02 16:13:09 | ||
* @Description: | ||
*/ | ||
|
||
import { Request, Response } from 'express' | ||
import { getApplicationByAppid, getMyApplications, getMyJoinedApplications } from '../../api/application' | ||
import { getPermissionsOfRoles } from '../../api/permission' | ||
import { Constants } from '../../constants' | ||
|
||
/** | ||
* The handler of getting my applications(created & joined) | ||
*/ | ||
export async function handleMyApplications(req: Request, res: Response) { | ||
const uid = req['auth']?.uid | ||
if (!uid) | ||
return res.status(401).send() | ||
|
||
const created = await getMyApplications(uid) | ||
const joined = await getMyJoinedApplications(uid) | ||
|
||
return res.send({ | ||
data: { | ||
created, | ||
joined | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* The handler of getting application by id | ||
* @param req | ||
* @param res | ||
* @returns | ||
*/ | ||
export async function handleGetApplicationByAppid(req: Request, res: Response) { | ||
const uid = req['auth']?.uid | ||
if (!uid) | ||
return res.status(401).send() | ||
|
||
const appid = req.params.appid | ||
const app = await getApplicationByAppid(appid) | ||
if (!app) | ||
return res.status(422).send('invalid appid') | ||
|
||
// return directly if the author here | ||
if (app.created_by === uid) { | ||
const roles = [Constants.roles.owner.name] | ||
const permissions = getPermissionsOfRoles(roles) | ||
return res.send({ | ||
data: { | ||
application: app, | ||
permissions, | ||
roles | ||
} | ||
}) | ||
} | ||
|
||
// reject if not the collaborator | ||
const [found] = app.collaborators.filter(co => co.uid === uid) | ||
if (!found) { | ||
return res.status(403).send() | ||
} | ||
|
||
const roles = found.roles | ||
const permissions = getPermissionsOfRoles(roles) | ||
|
||
return res.send({ | ||
data: { | ||
application: app, | ||
permissions, | ||
roles | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.