-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[NEW] add delete-own-message permission #15512
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
Changes from 1 commit
3db63f0
4537214
ade9e31
06928f5
436fad9
3ea1736
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { hasPermissionAsync } from './hasPermission'; | ||
| import { getValue } from '../../../settings/server/raw'; | ||
|
|
||
| const diff = (ts) => { | ||
| const dif = Date.now() - ts; | ||
| return Math.round((dif / 1000) / 60); | ||
| }; | ||
|
|
||
| const notAllowed = () => { | ||
| throw new Error('error-action-not-allowed'); | ||
| }; | ||
|
|
||
| export const canDeleteMessageAsync = async (uid, { u, rid, ts }) => { | ||
| const forceDelete = await hasPermissionAsync(uid, 'force-delete-message', rid); | ||
|
|
||
| if (forceDelete) { | ||
| return true; | ||
| } | ||
| const deleteAllowed = await getValue('Message_AllowDeleting'); | ||
|
|
||
| if (!deleteAllowed) { | ||
| return notAllowed(); | ||
| } | ||
|
|
||
| const allowedToDeleteAny = await hasPermissionAsync(uid, 'delete-message', rid); | ||
|
|
||
| const allowed = allowedToDeleteAny || (uid === u._id && await hasPermissionAsync(uid, 'delete-own-message')); | ||
| if (!allowed) { | ||
| return notAllowed(); | ||
| } | ||
| const blockDeleteInMinutes = await getValue('Message_AllowDeleting_BlockDeleteInMinutes'); | ||
|
|
||
| if (!blockDeleteInMinutes) { | ||
| return true; | ||
| } | ||
|
|
||
| if (ts == null) { | ||
| return notAllowed(); | ||
| } | ||
|
|
||
| const currentTsDiff = diff(ts); | ||
| if (currentTsDiff > blockDeleteInMinutes) { | ||
| throw new Error('error-message-deleting-blocked', 'Message deleting is blocked', { | ||
| method: 'deleteMessage', | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| export const canDeleteMessage = (uid, { u, rid, ts }) => Promise.await(canDeleteMessageAsync(uid, { u, rid, ts })); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ export function messageContext({ rid } = Template.instance()) { | |
| showreply: true, | ||
| showReplyButton: true, | ||
| hasPermissionDeleteMessage: hasPermission('delete-message', rid), | ||
| hasPermissionDeleteOwnMessage: hasPermission('delete-own-message'), | ||
|
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. is this being used somewhere?
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. not yet, but |
||
| hideRoles: !settings.get('UI_DisplayRoles') || getUserPreference(uid, 'hideRoles'), | ||
| UI_Use_Real_Name: settings.get('UI_Use_Real_Name'), | ||
| Chatops_Username: settings.get('Chatops_Username'), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.