-
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.
[NEW] Add an option to delete file in files list (#13815)
- Loading branch information
1 parent
14b79fe
commit 2143056
Showing
6 changed files
with
121 additions
and
70 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
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
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,42 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import moment from 'moment'; | ||
|
||
import { hasAtLeastOnePermission } from '../../../authorization/client'; | ||
import { settings } from '../../../settings/client'; | ||
|
||
export const canDeleteMessage = ({ rid, ts, uid }) => { | ||
const userId = Meteor.userId(); | ||
|
||
const forceDelete = hasAtLeastOnePermission('force-delete-message', rid); | ||
if (forceDelete) { | ||
return true; | ||
} | ||
|
||
const isDeleteAllowed = settings.get('Message_AllowDeleting'); | ||
if (!isDeleteAllowed) { | ||
return false; | ||
} | ||
|
||
const hasPermission = hasAtLeastOnePermission('delete-message', rid); | ||
const deleteOwn = uid === userId; | ||
if (!hasPermission && !deleteOwn) { | ||
return false; | ||
} | ||
|
||
const blockDeleteInMinutes = settings.get('Message_AllowDeleting_BlockDeleteInMinutes'); | ||
if (blockDeleteInMinutes != null && blockDeleteInMinutes !== 0) { | ||
let msgTs; | ||
if (ts != null) { | ||
msgTs = moment(ts); | ||
} | ||
let currentTsDiff; | ||
if (msgTs != null) { | ||
currentTsDiff = moment().diff(msgTs, 'minutes'); | ||
} | ||
return currentTsDiff < blockDeleteInMinutes; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
|
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 |
---|---|---|
@@ -1,47 +1,27 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Tracker } from 'meteor/tracker'; | ||
import { ChatMessage } from '../../app/models'; | ||
import { hasAtLeastOnePermission } from '../../app/authorization'; | ||
import { settings } from '../../app/settings'; | ||
import _ from 'underscore'; | ||
import moment from 'moment'; | ||
import { ChatMessage } from '../../app/models/client'; | ||
import { canDeleteMessage } from '../../app/utils/client'; | ||
|
||
Meteor.methods({ | ||
deleteMessage(message) { | ||
deleteMessage(msg) { | ||
if (!Meteor.userId()) { | ||
return false; | ||
} | ||
|
||
// We're now only passed in the `_id` property to lower the amount of data sent to the server | ||
message = ChatMessage.findOne({ _id: message._id }); | ||
const message = ChatMessage.findOne({ _id: msg._id }); | ||
|
||
const hasPermission = hasAtLeastOnePermission('delete-message', message.rid); | ||
const forceDelete = hasAtLeastOnePermission('force-delete-message', message.rid); | ||
const deleteAllowed = settings.get('Message_AllowDeleting'); | ||
let deleteOwn = false; | ||
|
||
if (message && message.u && message.u._id) { | ||
deleteOwn = message.u._id === Meteor.userId(); | ||
} | ||
if (!(forceDelete || hasPermission || (deleteAllowed && deleteOwn))) { | ||
if (!canDeleteMessage({ | ||
rid: message.rid, | ||
ts: message.ts, | ||
uid: message.u._id, | ||
})) { | ||
return false; | ||
} | ||
const blockDeleteInMinutes = settings.get('Message_AllowDeleting_BlockDeleteInMinutes'); | ||
if (!forceDelete && _.isNumber(blockDeleteInMinutes) && blockDeleteInMinutes !== 0) { | ||
const msgTs = moment(message.ts); | ||
const currentTsDiff = moment().diff(msgTs, 'minutes'); | ||
if (currentTsDiff > blockDeleteInMinutes) { | ||
return false; | ||
} | ||
|
||
|
||
} | ||
|
||
Tracker.nonreactive(function() { | ||
ChatMessage.remove({ | ||
_id: message._id, | ||
'u._id': Meteor.userId(), | ||
}); | ||
ChatMessage.remove({ | ||
_id: message._id, | ||
'u._id': Meteor.userId(), | ||
}); | ||
}, | ||
}); |