add admin section to select groups allowed to print
This commit is contained in:
parent
f854accbcc
commit
497a9f4892
8 changed files with 309 additions and 4 deletions
66
lib/Config.php
Normal file
66
lib/Config.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Printer;
|
||||
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* @var IConfig
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var ITimeFactory
|
||||
*/
|
||||
protected $timeFactory;
|
||||
|
||||
/**
|
||||
* @var IGroupManager
|
||||
*/
|
||||
private $groupManager;
|
||||
|
||||
/**
|
||||
* @var ISecureRandom
|
||||
*/
|
||||
private $secureRandom;
|
||||
|
||||
public function __construct(IConfig $config, ISecureRandom $secureRandom, IGroupManager $groupManager, ITimeFactory $timeFactory)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->secureRandom = $secureRandom;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->timeFactory = $timeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAllowedGroupIds(): array
|
||||
{
|
||||
$groups = $this->config->getAppValue('printer', 'allowed_groups', '[]');
|
||||
$groups = json_decode($groups, true);
|
||||
|
||||
return \is_array($groups) ? $groups : [];
|
||||
}
|
||||
|
||||
public function isDisabledForUser(IUser $user): bool
|
||||
{
|
||||
$allowedGroups = $this->getAllowedGroupIds();
|
||||
|
||||
if (empty($allowedGroups)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$userGroups = $this->groupManager->getUserGroupIds($user);
|
||||
|
||||
return empty(array_intersect($allowedGroups, $userGroups));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue