Skip to content

Commit

Permalink
overwrite flag and few adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jul 19, 2018
1 parent 90e5e04 commit 811b832
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 161 deletions.
Expand Up @@ -226,7 +226,24 @@
</div>
{{/with}}
</div>
{{# if settings.retentionEnabled.value.get }}
{{# if retentionEnabled settings.retentionEnabled.value.get }}
{{#with settings.retentionOverrideGlobal}}
<div class="rc-user-info__row">
<div class="rc-switch rc-switch--blue">
<label class="rc-switch__label">
<span class="rc-switch__text">
{{_ label}}{{equal default value '*'}}
</span>
<input type="checkbox" class="rc-switch__input js-input-check" name="retentionOverrideGlobal" checked="{{checked}}" disabled="{{./disabled}}">
<span class="rc-switch__button">
<span class="rc-switch__button-inside"></span>
</span>
</label>
</div>
</div>
{{/with}}
{{/if}}
{{# if settings.retentionOverrideGlobal.value.get }}
<div class="mail-messages__instructions mail-messages__instructions--warning" style="margin-bottom: 0;">
<div class="mail-messages__instructions-wrapper">
<div class="mail-messages__instructions-text">
Expand Down
Expand Up @@ -522,14 +522,31 @@ Template.channelSettingsEditing.onCreated(function() {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
},
save(value) {
return call('saveRoomSettings', room._id, 'retentionEnabled', value).then(
return call('saveRoomSettings', room._id, 'retentionEnabled', value).then(() => toastr.success(t('Retention_setting_changed_successfully')));
}
},
retentionOverrideGlobal: {
type: 'boolean',
label: 'RetentionPolicyRoom_OverrideGlobal',
isToggle: true,
processing: new ReactiveVar(false),
getValue() {
return Template.instance().room.retention && Template.instance().room.retention.overrideGlobal;
},
canView() {
return true;
},
canEdit() {
return RocketChat.authz.hasAllPermission('edit-privileged-setting', room._id);
},
disabled() {
return !RocketChat.authz.hasAllPermission('edit-privileged-setting', room._id);
},
save(value) {
return call('saveRoomSettings', room._id, 'retentionOverrideGlobal', value).then(
() => {
call('saveRoomSettings', room._id, 'retentionOverrideGlobal', value !== undefined).then(
() => {
toastr.success(
t('Retention_setting_changed_successfully')
);
}
toastr.success(
t('Retention_setting_changed_successfully')
);
}
);
Expand Down
14 changes: 4 additions & 10 deletions packages/rocketchat-lib/server/models/Messages.js
Expand Up @@ -756,9 +756,7 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base {
_id: 1
},
limit
}).map((document) => {
return document._id;
});
}).map(({ _id }) => _id);

return this.remove({
_id: {
Expand All @@ -776,18 +774,14 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base {
removeFilesByRoomId(roomId) {
this.find({
rid: roomId,
file: {
'file._id': {
$exists: true
}
}, {
fields: {
file: 1
}
}).fetch().map(function(document) {
if (document.file && document.file._id) {
FileUpload.getStore('Uploads').deleteById(document.file._id);
'file._id': 1
}
});
}).fetch().foreach(document => FileUpload.getStore('Uploads').deleteById(document.file._id));
}

getMessageByFileId(fileID) {
Expand Down
13 changes: 2 additions & 11 deletions packages/rocketchat-lib/server/models/Rooms.js
Expand Up @@ -658,23 +658,14 @@ class ModelRooms extends RocketChat.models._Base {
}

saveRetentionOverrideGlobalById(_id, value) {
const query = {_id};
const query = { _id };

let update = {
const update = {
$set: {
'retention.overrideGlobal': value === true
}
};

if (value === true && this.findOne({_id}, {'retention.maxAge': 1}).retention.maxAge === undefined) {
update = {
$set: {
'retention.overrideGlobal': value === true,
'retention.maxAge': 30
}
};
}

return this.update(query, update);
}

Expand Down
Expand Up @@ -41,7 +41,7 @@ function job() {
'retention.maxAge': { $gte: 0 },
_updatedAt: { $gte: lastPrune }
}).forEach(room => {
const { maxAge = 0, filesOnly, excludePinned } = room.retention;
const { maxAge = 30, filesOnly, excludePinned } = room.retention;
const latest = new Date(now.getTime() - maxAge * toDays);
RocketChat.cleanRoomHistory({ rid: room._id, latest, oldest, filesOnly, excludePinned });
});
Expand Down
Expand Up @@ -78,7 +78,7 @@
<div class="mail-messages__instructions-wrapper">
{{> icon block="mail-messages__instructions-icon" icon="warning"}}
<div class="mail-messages__instructions-text">
{{warningBox}}
{{warningBox}}
</div>
</div>
</div>
Expand Down

0 comments on commit 811b832

Please sign in to comment.