WYHNUS / ExchangeBuddy

Find your exchange buddies!
5 stars 0 forks source link

Admin roles and tokens #136

Open irvinlim opened 7 years ago

irvinlim commented 7 years ago

Is it possible to do this up quickly? Like using the role column in the Users table to determine user role. Then, endpoints which require admin rights would be deleting section.

WYHNUS commented 7 years ago

The role column was implemented since the beginning of ExchangeBuddy... Things need to be changed are backend role check and DB role assignment (0 being least privilege, 10 being the highest privilege(admin)).

irvinlim commented 7 years ago

Hmm, it was implemented since the start but is it being used? I'm ok with anything, just suggesting only.

WYHNUS commented 7 years ago

Never used as didn't have time to implement the admin page, but it is intended to be used for admin page. :)

WYHNUS commented 7 years ago

User role is currently designed to range from level 0 - 10 where 0 being the lowest privilege and 10 being the highest privilege. We should discuss on what privilege each level should has. @plsgibchance

For now, I implemented (hard-coded) admin privilege temporarily for createUniversity end-point, and assume anyone with role level 8 and above can add university.

@ZhangHanming @irvinlim Please help to assign necessary admins with corresponding privileges in User table role column.

irvinlim commented 7 years ago

@WYHNUS The admin privilege is being checked in the req.user.role property, but it's undefined, which causes it to pass the check (undefined < 8 == false). The req.user object looks like this:

{ id: 491,
  email: 'irvinlimweiquan@gmail.com',
  name: 'Irvin Lim',
  profilePictureUrl: 'https://scontent.xx.fbcdn.net/v/t1.0-1/p720x720/12744490_10154668045582575_8254141537094470326_n.jpg?oh=3225976ed7f71907c974cbcc5fc056e6&oe=58CCF01A',
  exp: 1482167290,
  iat: 1481562490 }

Hence, you need to fix the error + use parseInt.

WYHNUS commented 7 years ago

Can you clear cache and try again, coz role field should present in the signature. BTW, I've added a simple user.role validity check in the backend.