Skip to content
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

MEM-515 Block user from deleting published content (cleanup) #109

Merged
merged 2 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ angular.module('documents')
controllerAs: 'confirmDlg',
controller: function ($scope, $modalInstance) {
var NO_AUTH = "Not authorized to delete";
var WONT_PUBLISHED = "Published content will not be deleted";
var CANT_PUBLISHED = "Published content cannot be deleted";
var WONT_CONTENT = "Folders with content will not be deleted";
var CANT_CONTENT = "Folders with content cannot be deleted";
var UNDELETABLE = 'Any content showing a warning will not be deleted.';

var HAS_CONTENT = "Folder is not empty";
var IS_PUBLISHED = "Published content cannot be deleted";
var self = this;
/*
Set the following to true, during development, if you want to test the server side delete API.
Expand Down Expand Up @@ -103,7 +99,10 @@ angular.module('documents')

function checkFoldersForContent() {
var promises = [];
_.forEach(self.deletableFolders, function(fldr) {

//We check all folders (instead of just deletable folders) since a folder can be published and can have children
//In that case, we need to display two warnings
_.forEach(self.folders, function(fldr) {
// Does the folder have child folders? ....
var node = self.currentNode.first(function (child) {
return (child.model.id === fldr.model.id);
Expand Down Expand Up @@ -139,41 +138,37 @@ angular.module('documents')
var fileCnt = self.files.length;
var deletableFolderCnt = self.deletableFolders.length;
var deletableFileCnt = self.deletableFiles.length;
var CONFIRM_DELETE = "Confirm Delete File(s) and/or Folder(s)";
var CANNOT_DELETE = "Cannot Delete File(s) and/or Folder(s)";
var INFO_DELETE = "Files and folders must be unpublished before they can be deleted. <br/> Folders with content cannot be deleted.";
self.allBlocked = false;
self.hasBlockedContent = false;

if (deletableFolderCnt > 0 || deletableFileCnt > 0) {
self.title = CONFIRM_DELETE;
self.confirmText = "Are you sure you want to permanently delete the following file(s) and/or folder(s)? This action CANNOT be undone.";
if (folderCnt > deletableFolderCnt || fileCnt > deletableFileCnt ) {
self.hasBlockedContent = true;
self.bannerText = "Some content has been published. Content MUST be unpublished before it can be deleted";
self.confirmText += " " + UNDELETABLE;
}
var fText = deletableFileCnt > 1 ? "Files" : deletableFileCnt === 1 ? "File" : "";
var fldrText = deletableFolderCnt > 1 ? "Folders" : deletableFolderCnt === 1 ? "Folder" : "";
var combinedText = fText + ((fText && fldrText) ? " and " : "") + fldrText;
var confirmText = 'Are you sure you want to permanently delete the following ' + combinedText.toLowerCase() + '?';
var warning = 'This action CANNOT be undone.';
self.title = "Confirm Delete " + combinedText;
self.confirmText = confirmText + " " + warning;
if (self.hasBlockedContent) {
self.confirmText += " " + UNDELETABLE;
self.bannerText = INFO_DELETE;
self.title = CONFIRM_DELETE + "<br> " + CANNOT_DELETE;
self.confirmText += " <br/> Published content and folders with content will not be deleted.";
}
self.showSubmit = true;
self.cancelText = 'No';
self.cancelText = 'Cancel';
} else {
// No files and no folders can be deleted
self.allBlocked = true;
self.allBlocked = true;
if (self.testServerAPI) {
self.title = "Confirm Delete API Testing";
self.showSubmit = true;
self.cancelText = 'cancel';

} else {
self.title = "Published content cannot be deleted";
self.showSubmit = false;
self.cancelText = 'OK';
self.title = CANNOT_DELETE;
self.showSubmit = false;
self.cancelText = 'OK';
self.hasBlockedContent = true;
self.bannerText = "Content MUST be unpublished before it can be deleted";
self.bannerText = INFO_DELETE;
}
}
// update the text why a user can not delete an item...
Expand All @@ -188,9 +183,9 @@ angular.module('documents')
function setReasonForItem(item) {
if (!item.canBeDeleted) {
item.reason = (
!item.userCanDelete ? NO_AUTH :
item.isPublished ? (self.allBlocked ? CANT_PUBLISHED : WONT_PUBLISHED) :
item.hasChildren ? (self.allBlocked ? CANT_CONTENT : WONT_CONTENT) : ""
!item.userCanDelete ? NO_AUTH :
item.isPublished ? (item.hasChildren ? HAS_CONTENT + "<br/> "+ IS_PUBLISHED : IS_PUBLISHED) :
item.hasChildren ? HAS_CONTENT : ""
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
<button class="btn btn-default close" type="button" ng-click="confirmDlg.cancel()">
<span aria-hidden="true">&times;</span>
</button>
<h3 class="modal-title">{{confirmDlg.title}}</h3>
<h3 class="modal-title" ng-bind-html="confirmDlg.title">{{confirmDlg.title}}</h3>
</div>

<div class="modal-body" ng-if="confirmDlg.errMsg">
<div class="alert alert-danger" >{{confirmDlg.errMsg}}</div>
</div>

<div class="modal-body" ng-if="!confirmDlg.errMsg">
<div class="alert alert-danger" ng-if="confirmDlg.hasBlockedContent">{{confirmDlg.bannerText}}</div>
<div class="alert alert-danger" ng-if="confirmDlg.hasBlockedContent" ng-bind-html="confirmDlg.bannerText">{{confirmDlg.bannerText}}</div>

{{confirmDlg.confirmText}}
<div ng-bind-html="confirmDlg.confirmText">{{confirmDlg.confirmText}}</div>
<ul class="confirm-list">
<li ng-repeat="item in confirmDlg.combindedList">
<span class="avatar" ng-class="{'disabled': !item.canBeDeleted}">
Expand All @@ -26,14 +26,14 @@ <h3 class="modal-title">{{confirmDlg.title}}</h3>
<span class="fb-img glyphicon glyphicon-picture" ng-if="item.type === 'Picture'"></span>
</span>
<span class="item" ng-class="{'disabled': !item.canBeDeleted}" >{{item.displayName}}</span>
<span class="reason" ng-show="!item.canBeDeleted">{{item.reason}}</span>
<span class="reason" ng-show="!item.canBeDeleted" ng-bind-html="item.reason">{{item.reason}}</span>
</li>
</ul>
</div>

<div class="modal-footer">
<button class="btn btn-default" type="button" ng-click="confirmDlg.cancel()">{{confirmDlg.cancelText}}</button>
<button class="btn btn-primary" type="submit" ng-click="confirmDlg.submit()"
ng-show="confirmDlg.showSubmit" ng-disabled="confirmDlg.errMsg">Yes</button>
ng-show="confirmDlg.showSubmit" ng-disabled="confirmDlg.errMsg">Delete</button>
</div>
</form>