Skip to content

Commit

Permalink
#700 make sure only access option has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
schoicsiro committed Oct 6, 2023
1 parent f7f6f44 commit 175ce3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,23 @@ profileEditor.controller('UserAccessController', function (messageService, util,
});
};

self.privateModeChanged = function(form) {
self.privateModeChanged = function(form, isOptionChanged) {
if (self.opus.privateCollection) {
self.roles.push(userRole);
} else {
var hasRole_USER = self.users.find(it=>it.role === 'ROLE_USER')
if (hasRole_USER) {
self.users = self.users.filter(it => it.role !== 'ROLE_USER')
var data = {privateCollection: self.opus.privateCollection, authorities: self.users};
var promise = profileService.updateUsers(self.opusId, data);
promise.then(function () {
form.$setPristine();
messageService.success("User access has been successfully updated.");
}, function () {
messageService.alert("An error has occurred while updating user access.");
});
if (isOptionChanged) {
var hasRole_USER = self.users.find(it => it.role === 'ROLE_USER')
if (hasRole_USER) {
self.users = self.users.filter(it => it.role !== 'ROLE_USER')
var data = {privateCollection: self.opus.privateCollection, authorities: self.users};
var promise = profileService.updateUsers(self.opusId, data);
promise.then(function () {
form.$setPristine();
messageService.success("User access has been successfully updated.");
}, function () {
messageService.alert("An error has occurred while updating user access.");
});
}
}
self.roles.splice(4, 1)
}
Expand Down Expand Up @@ -124,10 +126,10 @@ profileEditor.controller('UserAccessController', function (messageService, util,
}

self.reset = function (form) {
loadOpus(form, true);
loadOpus(form);
};

function loadOpus(form, isReset) {
function loadOpus(form) {
if (!self.opusId) {
return;
}
Expand All @@ -143,9 +145,7 @@ profileEditor.controller('UserAccessController', function (messageService, util,
popupateUserDetails(user);
});

if (isReset) {
self.privateModeChanged(form);
}
self.privateModeChanged();

if (form) {
form.$setPristine();
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/opus/_editAccessControl.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="checkbox padding-bottom-1">
<label for="privateCollection" class="inline-label">
<input id="privateCollection" type="checkbox" name="privateCollection"
ng-change="userCtrl.privateModeChanged(UserForm)"
ng-change="userCtrl.privateModeChanged(UserForm, true)"
ng-model="userCtrl.opus.privateCollection" ng-false-value="false">
Make this collection private
</label>
Expand Down

0 comments on commit 175ce3b

Please sign in to comment.