Skip to content

Commit

Permalink
WIP group improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
oiseauroch committed Oct 2, 2024
1 parent 58ca677 commit 912b130
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
19 changes: 11 additions & 8 deletions includes/controllers/GroupController.php.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use YesWiki\Core\Exception\InvalidGroupNameException;
use YesWiki\Core\Exception\GroupNameDoesNotExistException;
use YesWiki\Core\Exception\GroupNameAlreadyUsedException;
use YesWiki\Core\Exception\UserNameAlreadyUsedException;
use YesWiki\Core\Exception\UserNameDoesNotExistException;
use YesWiki\Core\Service\GroupManager;
use YesWiki\Core\Service\UserManager;
use YesWiki\Core\YesWikiController;
Expand Down Expand Up @@ -60,7 +61,9 @@ class GroupController extends YesWikiController
if ($this->isNameValid($name))
{
$this->groupManager->create($name, $members);
} else
} else {
throw new InvalidGroupNameException(_t('INVALID_GROUP_NAME')); // FIXME vérifier INVALID_GROUP_NAME
}
}

/**
Expand All @@ -84,30 +87,30 @@ class GroupController extends YesWikiController
*/
public function addOne(string $group_name, string $name)
{
if(!$this->groupManager->groupExists()) {
if(!$this->groupManager->groupExists($group_name)) {
throw new GroupNameDoesNotExistException();
}
if(str_starts_with($name, "@") {
if($this->groupManager->groupExists()) {
throw new GroupNameAlreadyUsedException(_t('GROUP_NAME_ALREADY_USED'));
if(!$this->groupManager->groupExists($name)) {
throw new GroupNameDoesNotExistException(_t('GROUP_NAME_DOES_NOT_EXIST')); // FIXME voir GROUP_NAME_DOES_NOT_EXIST
}
} else {
if($this->userManager->userExist()) {
throw new UserNameAlreadyUsedException(_t('USER_NAME_ALREADY_USED'));
if(!$this->userManager->userExist($name)) {
throw new UserNameDoesNotExistException(_t('USER_NAME_DOES_NOT_EXIST')); // FIXME voir USER_NAME_DOES_NOT_EXIST
}
}

$this->groupManager->add($group_name, $name);
}

/**
* remove user or group from group
* @param string $$group_name group to remove from
* @param string $name user or group to remove
* @return bool
* @throws UserDoesNotExistException
* @throws GroupDoesNotExistException
*/
public function removeOne(string $name)
public function removeOne(string $group_name, string $name)
{

}
Expand Down
9 changes: 9 additions & 0 deletions includes/exceptions/UserNameDoesNotExistException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace YesWiki\Core\Exception;

use Exception;

class UserNameDoesNotExistException extends Exception
{
}
21 changes: 16 additions & 5 deletions includes/services/GroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
*/
public function groupExists(string $group_name): bool
{
return $this->tripleStore->getOne($group_name, WIKINI_VOC_ACLS, GROUP_PREFIX) == null;
return $this->tripleStore->getOne($group_name, WIKINI_VOC_ACLS, GROUP_PREFIX) != null;
}

/**
Expand All @@ -36,7 +36,12 @@ public function create(string $group_name, array $members): void {
$member_str = implode("\n", $members);
$this->tripleStore->create($group_name, WIKINI_VOC_ACLS, $member_str, GROUP_PREFIX);
}


/**
* get direct members of group. Do not list member of child groups.
* @param string group_name
* @return string[]
*/
public function getMembers(string $group_name) :array {
$members = $this->tripleStore->getOne($group_name, WIKINI_VOC_ACLS, GROUP_PREFIX);
return explode("\n", $members);
Expand All @@ -50,14 +55,20 @@ public function getMembers(string $group_name) :array {
public function add(string $group_name, array $members):void {
$old_members = $this->getMembers($group_name);
if (!in_array($group_name, $members) ) {
$new_members = implode("\n", $members);
$new_members = $old_members . "\n" . $new_members;
$new_members = array_merge($old_members, $members);
$new_members = array_unique($$new_members);
$new_members = implode("\n", $new_members);
if($this->tripleStore->delete($group_name, WIKINI_VOC_ACLS, $old_members, GROUP_PREFIX)) {
$this->tripleStore->create($group_name, WIKINI_VOC_ACLS, $new_members, GROUP_PREFIX);
} else {
$this->tripleStore->update($group_name, WIKINI_VOC_ACLS, $old_members, $new_members , GROUP_PREFIX)
$this->tripleStore->update($group_name, WIKINI_VOC_ACLS, $old_members, $new_members , GROUP_PREFIX);
}
}
}

public function remove(string $group_name, string $member): void {
$old_members = $this->getMembers($group_name);

}

}
2 changes: 1 addition & 1 deletion includes/services/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private function arrayToUser(?array $userAsArray = null, bool $fillEmpty = false
}

public function userExist($name): bool {
return !empty($this->getOneByName($name))
return !empty($this->getOneByName($name));
}

public function getOneByName($name, $password = null): ?User
Expand Down

0 comments on commit 912b130

Please sign in to comment.