Skip to content

Commit 7aa5f4d

Browse files
authored
Merge pull request #182 from osamhack2021/feature/backend
Modify item access logic, extend token expiry
2 parents bfcb3fa + ea3937e commit 7aa5f4d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

β€Žbackend/controllers/itemController.jsβ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = {
5454

5555
// Check session's read authority
5656
const user = await userService.findOne({ serviceNumber: res.locals.serviceNumber });
57-
if(!item.accessGroups.read.some(i => i.equals(user.group)))
57+
if(!item.accessGroups.read.some(i => i.equals(user.group)) && item.owner._id !== res.locals._id)
5858
throw new ForbiddenError(`Access denied: μ—΄λžŒ κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.`);
5959

6060
res.status(200).send(item);
@@ -109,7 +109,7 @@ module.exports = {
109109
if(item === null) throw new NotFoundError(`Item not Found: μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν•­λͺ©μž…λ‹ˆλ‹€.`);
110110

111111
// Check session's edit authority
112-
if(!item.accessGroups.edit.some(i => i.equals(res.locals.group)))
112+
if(!item.accessGroups.edit.some(i => i.equals(res.locals.group)) && item.owner._id !== res.locals._id)
113113
throw new ForbiddenError(`Access denied: μˆ˜μ • κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.`);
114114

115115
// Append Contributor
@@ -137,6 +137,10 @@ module.exports = {
137137

138138
if(item === null)
139139
throw new NotFoundError(`Item not Found: μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν•­λͺ©μž…λ‹ˆλ‹€.`);
140+
141+
// Check session's delete authority
142+
if(item.owner._id !== res.locals._id)
143+
throw new ForbiddenError(`Access denied: μ‚­μ œ κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.`);
140144

141145
// Algolia
142146
await algolia.deleteObject(item_id);

β€Žbackend/services/authService.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports = {
109109
group: loginUser.group,
110110
status: loginUser.status,
111111
}, JWT_SECRET_KEY, {
112-
expiresIn: '1h',
112+
expiresIn: '12h',
113113
});
114114

115115
return user;

0 commit comments

Comments
Β (0)