Skip to content

Commit

Permalink
fix: update permissions for institutional managers (#219)
Browse files Browse the repository at this point in the history
* fix: update permissions for institutional managers

* chore(l10n): update pot file

* remove edit link for inst managers

* chore(l10n): update pot file

---------

Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: Oscar Arzola <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 021e8ee commit 7159fd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions languages/pressbooks-multi-institution.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-12-11T16:13:45+00:00\n"
"POT-Creation-Date: 2024-12-18T01:26:07+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.11.0\n"
"X-Domain: pressbooks-multi-institution\n"
Expand Down Expand Up @@ -137,7 +137,7 @@ msgstr ""
msgid "Administer Institution"
msgstr ""

#: src/Services/PermissionsManager.php:95
#: src/Services/PermissionsManager.php:104
msgid "Sorry, you are not allowed to access this page."
msgstr ""

Expand Down
14 changes: 14 additions & 0 deletions src/Services/PermissionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function setupFilters(): void
Container::get(UserList::class)->init();

do_action('pb_institutional_filters_created', $institution, $institutionalManagers, $institutionalUsers);

// Hide the edit link on the front end for institutional managers
add_filter('edit_post_link', function ($link) use ($institution) {
// If the user is a regular super admin, return the link
if ($institution === 0) {
return $link;
}
return '';
});
}

public function handlePagesPermissions($institution, $institutionalManagers, $institutionalUsers): void
Expand Down Expand Up @@ -197,6 +206,11 @@ private function currentUserHasAccess(string $currentPageParam, array $allowedBo
}
}

// Prevent institutional managers from editing pages on the root site
if ($currentBlogId === 1 && ($pagenow === 'edit.php' || $pagenow === 'post.php')) {
$isAccessAllowed = false;
}

return $isAccessAllowed;
}
}
3 changes: 2 additions & 1 deletion src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function get_allowed_pages(): array
'users.php',
'export-personal-data.php',
'erase-personal-data.php',
'options-privacy.php'
'options-privacy.php',
'site-new.php'
];
}

Expand Down

0 comments on commit 7159fd6

Please sign in to comment.