-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: implement new role for admin #122
Changes from 2 commits
f7a656a
117df28
00ded06
fd97043
80cc7cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ const UserSchema = new mongoose.Schema( | |
}, | ||
role: { | ||
type: String, | ||
enum: ['ADMIN', 'GROUP'], | ||
enum: ['ADMIN', 'GROUP', 'SPECTATOR'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this into an enum like object and use it here with Object.Values() |
||
default: 'GROUP' | ||
}, | ||
members: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import express from 'express'; | ||
import { adminProtect, protect } from '@/middleware/auth'; | ||
import { adminProtect, externalPartyProtect, protect } from '@/middleware/auth'; | ||
import authRouter from './auth.routes'; | ||
import dashboardRouter from './dashboard.routes'; | ||
import leaderboardRouter from './leaderboard.routes'; | ||
|
@@ -15,7 +15,7 @@ router.use('/auth', authRouter); | |
router.use('/submissions', protect, submissionRouter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Submission grade will have to be restricted as well for role |
||
router.use('/users', protect, userRouter); | ||
router.use('/questions', protect, questionRouter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question create update will have to be restricted as well for role |
||
router.use('/dashboard', protect, adminProtect, dashboardRouter); | ||
router.use('/dashboard', protect, externalPartyProtect, adminProtect, dashboardRouter); | ||
router.use('/leaderboard', leaderboardRouter); | ||
router.use('/settings', protect, settingRouter); | ||
router.use('/storage', protect, adminProtect, storageRouter); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import express from 'express'; | |
import { tracedAsyncHandler } from '@sliit-foss/functions'; | ||
import { Segments, celebrate } from 'celebrate'; | ||
import { changePassword, create, eliminateTeams, getAll, getById, update } from '@/controllers/user'; | ||
import { adminProtect } from '@/middleware/auth'; | ||
import { adminProtect, externalPartyProtect } from '@/middleware/auth'; | ||
import { | ||
addUserSchema, | ||
changePasswordSchema, | ||
|
@@ -14,7 +14,7 @@ import { | |
const users = express.Router(); | ||
|
||
users.post('/', adminProtect, celebrate({ [Segments.BODY]: addUserSchema }), tracedAsyncHandler(create)); | ||
users.get('/', adminProtect, tracedAsyncHandler(getAll)); | ||
users.get('/', externalPartyProtect, adminProtect, tracedAsyncHandler(getAll)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhere below there's a user update route as well I guess that needs restriction as well |
||
users.get('/:id', celebrate({ [Segments.PARAMS]: userIdSchema }), adminProtect, tracedAsyncHandler(getById)); | ||
users.patch( | ||
'/change_password', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ import { genders, mealPreferences } from '@/models/user'; | |
|
||
export const addUserSchema = { | ||
name: Joi.string().required(), | ||
email: Joi.string().email().required() | ||
email: Joi.string().email().required(), | ||
role: Joi.string().valid('ADMIN', 'SPECTATOR').required() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like in the model, can we move this into an enum like object and use it here with Object.Values() |
||
}; | ||
|
||
export const userIdSchema = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is used along with adminProtect neither of it will allow the call to go through, since each checks for a different role, can we refactor this into a function like
roleProtect
which takes in a list of accepted roles and checks accordingly ?