mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 01:41:13 +08:00
Merge pull request #172 from coralproject/login-fix
The current user can see their own roles.
This commit is contained in:
+7
-1
@@ -136,7 +136,13 @@ UserSchema.options.toJSON.transform = (doc, ret, options) => {
|
||||
*/
|
||||
UserSchema.method('filterForUser', function(user = false) {
|
||||
if (!user || !user.roles.includes('admin')) {
|
||||
return _.pick(this.toJSON(), ['id', 'displayName', 'settings', 'created_at', 'updated_at']);
|
||||
let allowed = ['id', 'displayName', 'settings', 'created_at', 'updated_at'];
|
||||
|
||||
if (user && user.id === this.id) {
|
||||
allowed.push('roles');
|
||||
}
|
||||
|
||||
return _.pick(this.toJSON(), allowed);
|
||||
}
|
||||
|
||||
return this.toJSON();
|
||||
|
||||
Reference in New Issue
Block a user