Skip to content

Commit b2580d8

Browse files
committed
Feat: Modify item access authorization
Add read access to owners Restrict delete access to only owners
1 parent bfcb3fa commit b2580d8

1 file changed

Lines changed: 6 additions & 2 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);

0 commit comments

Comments
Β (0)