forked from mrsimpson/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Apply changed setting permissions reactively
- Loading branch information
Showing
4 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/rocketchat-ui-admin/client/SettingsCachedCollection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import _ from 'underscore'; | ||
|
||
export class PrivateSettingsCachedCollection extends RocketChat.CachedCollection { | ||
constructor() { | ||
super({ | ||
name: 'private-settings', | ||
eventType: 'onLogged' | ||
}); | ||
} | ||
|
||
setupListener(eventType, eventName) { | ||
super.setupListener(eventType, eventName); | ||
|
||
// private settings also need to listen to a change of authorizationsfor the setting-based authorizations | ||
RocketChat.Notifications[eventType || this.eventType](eventName || this.eventName, (t, record) => { | ||
this.log('record received', t, record); | ||
if (t === 'auth') { | ||
if (! (RocketChat.authz.hasAllPermission([`change-setting-${ record._id }`, 'manage-selected-settings']) | ||
|| RocketChat.authz.hasAllPermission('view-privileged-setting'))) { | ||
this.collection.remove(record._id); | ||
RoomManager.close(record.t + record.name); | ||
} else { | ||
delete record.$loki; | ||
this.collection.upsert({_id: record._id}, _.omit(record, '_id')); | ||
} | ||
|
||
this.saveCache(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters