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

Prevent departmental accounts from being added as admins #1034

Merged
merged 1 commit into from
Oct 1, 2024
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
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ screen.message.modal.access.opt.feedback=If the error persists please refer to o

# Modal Add
screen.message.modal.add.deptAccount=One or more departmental accounts are being added.
screen.message.modal.add.deptAccount.admin=Departmental accounts cannot be assigned as admins.
screen.message.modal.add.fail=There was an error adding:
screen.message.modal.add.ensureValid=Please ensure you have entered a valid UH member and try again.
screen.message.modal.add.empty=You must enter a UH member to add or remove.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@
}

groupingsService.getMemberAttributeResults([sanitizedAdmin], (res) => {
// Prevent departmental accounts from being added as admins
$scope.isDeptAccount = $scope.checkForDeptAccount(res.results);
if ($scope.isDeptAccount) {
$scope.containsDeptAcc = true;
return;
}
$scope.displayAddModal({
membersAttributes: res,
uhIdentifiers: sanitizedAdmin,
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/static/javascript/mainApp/general.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
$scope.emptySelect = false;
$scope.containsInput = false;
$scope.invalidInput = false;
$scope.containsDeptAcc = false;
$scope.addInputError = false;
$scope.removeInputError = false;
};
Expand Down Expand Up @@ -295,6 +296,17 @@
});
};

/**
* Checks if a member is a departmental account
* A departmental account is characterized by having the same uid as its uhUuid, or having a blank uhUuid
* @param {object[]} membersToAdd - members to add to a group or admin
* @returns {boolean} - True if a member is a departmental account
*/
$scope.checkForDeptAccount = (membersToAdd) => {
return membersToAdd.some(member =>
member['uid'] === member['uhUuid'] || member['uhUuid'] === ""
);
}
}

UHGroupingsApp.controller("GeneralJsController", GeneralJsController);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1836,19 +1836,6 @@
$scope.excludeDisable = true;
}
};

/**
* Helper - addMembers, displayAddModal
* Checks if a member is a departmental account
* A departmental account is characterized by having the same uid as its uhUuid, or having a blank uhUuid
* @param {object[]} membersToAdd - members to add to group
* @returns {boolean} - True if a member is a departmental account
*/
$scope.checkForDeptAccount = (membersToAdd) => {
return membersToAdd.some(member =>
member['uid'] === member['uhUuid'] || member['uhUuid'] === ""
);
}
}

function SyncDestModalController($scope, $uibModalInstance, isSynced, syncDestDescription, Message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
role="alert">
<p th:text="#{screen.message.modal.add.preExisting.admin}"></p>
</div>
<!--message for trying to add a departmental account-->
<div ng-if="containsDeptAcc"
class="float-md-left my-3 px-3 pt-2 rounded alert-danger show"
role="alert">
<p th:text="#{screen.message.modal.add.deptAccount.admin}"></p>
</div>
<!--message for no groupings result-->
<div ng-if="resStatus && subjectToLookup.length > 0 && subjectList.length <= 0"
class="float-md-left my-3 px-3 pt-2 rounded alert-danger show">
Expand Down
17 changes: 15 additions & 2 deletions src/test/javascript/admin.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,25 @@ describe("AdminController", function () {
expect(scope.containsInput).toBeTrue();
});

it("should check if the admin to add is a departmental account", () => {
scope.containsDeptAcc = false;
scope.adminToAdd = "testiwt2";
scope.addAdmin();

httpBackend.expectPOST(BASE_URL + "members", ['testiwt2']).respond(200, results);
httpBackend.flush();

expect(scope.user).toBe(scope.adminToAdd);
expect(scope.containsDeptAcc).toBeTrue();
});

it("should display the add modal", () => {
spyOn(scope, "displayAddModal");
scope.adminToAdd = uhIdentifiers;
scope.adminToAdd = "testiwta";
scope.addAdmin();

httpBackend.expectPOST(BASE_URL + "members", [uhIdentifiers]).respond(200, results);
const results = { resultCode: "SUCCESS", invalid: [], results: [{ uid: "testiwta", uhUuid: "99997010" }] };
httpBackend.expectPOST(BASE_URL + "members", ['testiwta']).respond(200, results);
httpBackend.flush();

expect(scope.user).toEqual(scope.adminToAdd);
Expand Down
Loading