123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace OCA\User_LDAP;
- use OCP\GroupInterface;
- class GroupPluginManager {
- private int $respondToActions = 0;
-
- private array $which = [
- GroupInterface::CREATE_GROUP => null,
- GroupInterface::DELETE_GROUP => null,
- GroupInterface::ADD_TO_GROUP => null,
- GroupInterface::REMOVE_FROM_GROUP => null,
- GroupInterface::COUNT_USERS => null,
- GroupInterface::GROUP_DETAILS => null
- ];
- private bool $suppressDeletion = false;
-
- public function getImplementedActions() {
- return $this->respondToActions;
- }
-
- public function register(ILDAPGroupPlugin $plugin) {
- $respondToActions = $plugin->respondToActions();
- $this->respondToActions |= $respondToActions;
- foreach ($this->which as $action => $v) {
- if ((bool)($respondToActions & $action)) {
- $this->which[$action] = $plugin;
- \OC::$server->getLogger()->debug("Registered action ".$action." to plugin ".get_class($plugin), ['app' => 'user_ldap']);
- }
- }
- }
-
- public function implementsActions($actions) {
- return ($actions & $this->respondToActions) == $actions;
- }
-
- public function createGroup($gid) {
- $plugin = $this->which[GroupInterface::CREATE_GROUP];
- if ($plugin) {
- return $plugin->createGroup($gid);
- }
- throw new \Exception('No plugin implements createGroup in this LDAP Backend.');
- }
- public function canDeleteGroup(): bool {
- return !$this->suppressDeletion && $this->implementsActions(GroupInterface::DELETE_GROUP);
- }
-
- public function setSuppressDeletion(bool $value): bool {
- $old = $this->suppressDeletion;
- $this->suppressDeletion = $value;
- return $old;
- }
-
- public function deleteGroup(string $gid): bool {
- $plugin = $this->which[GroupInterface::DELETE_GROUP];
- if ($plugin) {
- if ($this->suppressDeletion) {
- return false;
- }
- return $plugin->deleteGroup($gid);
- }
- throw new \Exception('No plugin implements deleteGroup in this LDAP Backend.');
- }
-
- public function addToGroup($uid, $gid) {
- $plugin = $this->which[GroupInterface::ADD_TO_GROUP];
- if ($plugin) {
- return $plugin->addToGroup($uid, $gid);
- }
- throw new \Exception('No plugin implements addToGroup in this LDAP Backend.');
- }
-
- public function removeFromGroup($uid, $gid) {
- $plugin = $this->which[GroupInterface::REMOVE_FROM_GROUP];
- if ($plugin) {
- return $plugin->removeFromGroup($uid, $gid);
- }
- throw new \Exception('No plugin implements removeFromGroup in this LDAP Backend.');
- }
-
- public function countUsersInGroup($gid, $search = '') {
- $plugin = $this->which[GroupInterface::COUNT_USERS];
- if ($plugin) {
- return $plugin->countUsersInGroup($gid,$search);
- }
- throw new \Exception('No plugin implements countUsersInGroup in this LDAP Backend.');
- }
-
- public function getGroupDetails($gid) {
- $plugin = $this->which[GroupInterface::GROUP_DETAILS];
- if ($plugin) {
- return $plugin->getGroupDetails($gid);
- }
- throw new \Exception('No plugin implements getGroupDetails in this LDAP Backend.');
- }
- }
|