Skip to content

Commit

Permalink
Merge pull request #150 from AlexanderBlanchardAC/25.01.00_custom_for…
Browse files Browse the repository at this point in the history
…m_permissions

25.01.00 custom form permissions
  • Loading branch information
AlexanderBlanchardAC authored Dec 17, 2024
2 parents 5ef5ae3 + 3884f0c commit 61eb522
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions code/web/release_notes/25.01.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//james

//alexander
### Web Builder Updates
- When adding a form to a custom page, limit the forms displayed in the dropdown to those from the user's own library if their permissions are Administer Library Custom Forms. (*AB*)

//chloe

Expand Down
31 changes: 31 additions & 0 deletions code/web/services/WebBuilder/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@ function getPortalCellValuesForSource() {

$customForm = new CustomForm();
$customForm->orderBy('title');
if (!UserAccount::userHasPermission('Administer All Custom Forms')) {
$libraryCustomForm = new LibraryCustomForm();
$userLibrary = Library::getPatronHomeLibrary();

if ($userLibrary) {
$userLibraryId = $userLibrary->libraryId;
$libraryCustomForm->whereAdd('libraryId = ' . $userLibraryId);

$validCustomForms = [];
$libraryCustomForm->find();
while ($libraryCustomForm->fetch()) {
$validCustomForms[] = $libraryCustomForm->formId;
}

if (count($validCustomForms) > 0) {
$customForm->whereAddIn('id', $validCustomForms, true);
} else {
$result = [
'success' => true,
'values' => $list,
];
break;
}
} else {
$result = [
'success' => false,
'message' => 'Unable to determine the home library for this user.',
];
break;
}
}
$customForm->find();

while ($customForm->fetch()) {
Expand Down

0 comments on commit 61eb522

Please sign in to comment.