-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[FIX] Uncessary updates on Settings, Roles and Permissions on startup #17160
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
49dfad0
[FIX] Uncessary updates on Settings, Roles and Permissions on startup
rodrigok 4f5bba7
Fix update of permissions
rodrigok 8f35512
Rename files for the TS commit
rodrigok 9bbf059
Convert Settings to TS
rodrigok dd6932a
Show stack on API error when testing
rodrigok dde16b0
Fix tests
rodrigok 80f84f0
Merge remote-tracking branch 'origin/develop' into settings-permissio…
rodrigok 2f73e1b
Add unit tests
rodrigok e97536b
Improve overwrite test
rodrigok a9e1bc7
Add more tests
rodrigok 6634755
Merge branch 'develop' into settings-permissions-roles-updates
sampaiodiego c1e1f85
Remove types from tsconfig
sampaiodiego d5a6b9f
Use Map for settings callbacks
rodrigok d630bbe
Do not always update the role’s description and mandatory2fa
rodrigok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| /* eslint no-multi-spaces: 0 */ | ||
| import { Meteor } from 'meteor/meteor'; | ||
|
|
||
| import { Roles, Permissions, Settings } from '../../models'; | ||
| import { Roles, Permissions, Settings } from '../../models/server'; | ||
| import { settings } from '../../settings/server'; | ||
| import { getSettingPermissionId, CONSTANTS } from '../lib'; | ||
| import { clearCache } from './functions/hasPermission'; | ||
|
|
@@ -114,9 +114,7 @@ Meteor.startup(function() { | |
| ]; | ||
|
|
||
| for (const permission of permissions) { | ||
| if (!Permissions.findOneById(permission._id)) { | ||
| Permissions.upsert(permission._id, { $set: permission }); | ||
| } | ||
| Permissions.create(permission._id, permission.roles); | ||
| } | ||
|
|
||
| const defaultRoles = [ | ||
|
|
@@ -134,7 +132,7 @@ Meteor.startup(function() { | |
| ]; | ||
|
|
||
| for (const role of defaultRoles) { | ||
| Roles.upsert({ _id: role.name }, { $setOnInsert: { scope: role.scope, description: role.description || '', protected: true, mandatory2fa: false } }); | ||
| Roles.createOrUpdate(role.name, role.scope, role.description, true, false); | ||
| } | ||
|
|
||
| const getPreviousPermissions = function(settingId) { | ||
|
|
@@ -155,27 +153,34 @@ Meteor.startup(function() { | |
| const createSettingPermission = function(setting, previousSettingPermissions) { | ||
| const permissionId = getSettingPermissionId(setting._id); | ||
| const permission = { | ||
| _id: permissionId, | ||
| level: CONSTANTS.SETTINGS_LEVEL, | ||
| // copy those setting-properties which are needed to properly publish the setting-based permissions | ||
| settingId: setting._id, | ||
| group: setting.group, | ||
| section: setting.section, | ||
| sorter: setting.sorter, | ||
| roles: [], | ||
| }; | ||
| // copy previously assigned roles if available | ||
| if (previousSettingPermissions[permissionId] && previousSettingPermissions[permissionId].roles) { | ||
| permission.roles = previousSettingPermissions[permissionId].roles; | ||
| } else { | ||
| permission.roles = []; | ||
| } | ||
| if (setting.group) { | ||
| permission.groupPermissionId = getSettingPermissionId(setting.group); | ||
| } | ||
| if (setting.section) { | ||
| permission.sectionPermissionId = getSettingPermissionId(setting.section); | ||
| } | ||
| Permissions.upsert(permission._id, { $set: permission }); | ||
|
|
||
| const existent = Permissions.findOne({ | ||
| _id: permissionId, | ||
| ...permission, | ||
| }, { fields: { _id: 1 } }); | ||
|
|
||
| if (!existent) { | ||
| Permissions.upsert({ _id: permissionId }, { $set: permission }); | ||
|
Member
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. insert?
Member
Author
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. The permission may exist with different properties |
||
| } | ||
|
|
||
| delete previousSettingPermissions[permissionId]; | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,50 @@ | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import { ReactiveDict } from 'meteor/reactive-dict'; | ||
|
|
||
| import { CachedCollection } from '../../../ui-cached-collection'; | ||
| import { SettingsBase, SettingValue } from '../../lib/settings'; | ||
|
|
||
| const cachedCollection = new CachedCollection({ | ||
| name: 'public-settings', | ||
| eventType: 'onAll', | ||
| userRelated: false, | ||
| listenChangesForLoggedUsersOnly: true, | ||
| }); | ||
|
|
||
| class Settings extends SettingsBase { | ||
| cachedCollection = cachedCollection | ||
|
|
||
| collection = cachedCollection.collection; | ||
|
|
||
| dict = new ReactiveDict<any>('settings'); | ||
|
|
||
| get(_id: string): any { | ||
| return this.dict.get(_id); | ||
| } | ||
|
|
||
| init(): void { | ||
| let initialLoad = true; | ||
| this.collection.find().observe({ | ||
| added: (record: {_id: string; value: SettingValue}) => { | ||
| Meteor.settings[record._id] = record.value; | ||
| this.dict.set(record._id, record.value); | ||
| this.load(record._id, record.value, initialLoad); | ||
| }, | ||
| changed: (record: {_id: string; value: SettingValue}) => { | ||
| Meteor.settings[record._id] = record.value; | ||
| this.dict.set(record._id, record.value); | ||
| this.load(record._id, record.value, initialLoad); | ||
| }, | ||
| removed: (record: {_id: string}) => { | ||
| delete Meteor.settings[record._id]; | ||
| this.dict.set(record._id, null); | ||
| this.load(record._id, undefined, initialLoad); | ||
| }, | ||
| }); | ||
| initialLoad = false; | ||
| } | ||
| } | ||
|
|
||
| export const settings = new Settings(); | ||
|
|
||
| settings.init(); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import { Meteor } from 'meteor/meteor'; | ||
|
|
||
| if (Meteor.isClient) { | ||
| module.exports = require('./client/index.js'); | ||
| module.exports = require('./client/index.ts'); | ||
| } | ||
| if (Meteor.isServer) { | ||
| module.exports = require('./server/index.js'); | ||
| module.exports = require('./server/index.ts'); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.