Skip to content

Commit

Permalink
Moved dept acc check function to general controller (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarellb authored Oct 1, 2024
1 parent 23dc0e4 commit 14bcc89
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
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 @@ -137,6 +137,7 @@
$scope.emptySelect = false;
$scope.containsInput = false;
$scope.invalidInput = false;
$scope.containsDeptAcc = false;
$scope.addInputError = false;
$scope.removeInputError = false;
};
Expand Down Expand Up @@ -283,6 +284,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

0 comments on commit 14bcc89

Please sign in to comment.