-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
314 additions
and
272 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
app/authorization/server/publications/permissions/emitter.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,24 @@ | ||
import { Notifications } from '../../../../notifications'; | ||
import Permissions from '../../../../models/server/models/Permissions'; | ||
|
||
Permissions.on('change', ({ clientAction, id, data, diff }) => { | ||
if (diff && Object.keys(diff).length === 1 && diff._updatedAt) { // avoid useless changes | ||
return; | ||
} | ||
switch (clientAction) { | ||
case 'updated': | ||
case 'inserted': | ||
data = data || Permissions.findOneById(id); | ||
break; | ||
|
||
case 'removed': | ||
data = { _id: id }; | ||
break; | ||
} | ||
|
||
Notifications.notifyLoggedInThisInstance( | ||
'permissions-changed', | ||
clientAction, | ||
data | ||
); | ||
}); |
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
This file was deleted.
Oops, something went wrong.
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
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,37 @@ | ||
import { Rooms, Subscriptions } from '../../../app/models'; | ||
import { Notifications } from '../../../app/notifications'; | ||
|
||
import { fields } from '.'; | ||
|
||
const getSubscriptions = (id) => { | ||
const fields = { 'u._id': 1 }; | ||
return Subscriptions.trashFind({ rid: id }, { fields }); | ||
}; | ||
|
||
Rooms.on('change', ({ clientAction, id, data }) => { | ||
switch (clientAction) { | ||
case 'updated': | ||
case 'inserted': | ||
// Override data cuz we do not publish all fields | ||
data = Rooms.findOneById(id, { fields }); | ||
break; | ||
|
||
case 'removed': | ||
data = { _id: id }; | ||
break; | ||
} | ||
|
||
if (data) { | ||
if (clientAction === 'removed') { | ||
getSubscriptions(clientAction, id).forEach(({ u }) => { | ||
Notifications.notifyUserInThisInstance( | ||
u._id, | ||
'rooms-changed', | ||
clientAction, | ||
data | ||
); | ||
}); | ||
} | ||
Notifications.streamUser.__emit(id, clientAction, data); | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Settings } from '../../../app/models'; | ||
import { Notifications } from '../../../app/notifications'; | ||
import { hasPermission } from '../../../app/authorization'; | ||
|
||
Settings.on('change', ({ clientAction, id, data, diff }) => { | ||
if (diff && Object.keys(diff).length === 1 && diff._updatedAt) { // avoid useless changes | ||
return; | ||
} | ||
switch (clientAction) { | ||
case 'updated': | ||
case 'inserted': { | ||
const setting = data || Settings.findOneById(id); | ||
const value = { | ||
_id: setting._id, | ||
value: setting.value, | ||
editor: setting.editor, | ||
properties: setting.properties, | ||
}; | ||
|
||
if (setting.public === true) { | ||
Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, value); | ||
} | ||
Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, setting); | ||
break; | ||
} | ||
|
||
case 'removed': { | ||
const setting = data || Settings.findOneById(id, { fields: { public: 1 } }); | ||
|
||
if (setting && setting.public === true) { | ||
Notifications.notifyAllInThisInstance('public-settings-changed', clientAction, { _id: id }); | ||
} | ||
Notifications.notifyLoggedInThisInstance('private-settings-changed', clientAction, { _id: id }); | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
|
||
Notifications.streamAll.allowRead('private-settings-changed', function() { | ||
if (this.userId == null) { | ||
return false; | ||
} | ||
return hasPermission(this.userId, 'view-privileged-setting'); | ||
}); |
Oops, something went wrong.