Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set a default client per group #1888

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/locales/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
5 changes: 5 additions & 0 deletions app/locales/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -4950,6 +4950,7 @@ msgstr "Permissions"
#: app/modules/web/themes/material-blue/views/account/account.inc:100
#: app/modules/web/themes/material-blue/views/account/search-searchbox.inc:43
#: app/modules/web/themes/material-blue/views/itemshow/account_bulkedit.inc:51
#: app/modules/web/themes/material-blue/views/itemshow/user_group.inc:66
msgid "Select Client"
msgstr "Select Client"

Expand Down Expand Up @@ -5571,6 +5572,10 @@ msgstr "Domain name"
msgid "Default Group"
msgstr "Default Group"

#: app/modules/web/themes/material-blue/views/itemshow/user_group.inc:60
msgid "Default Client"
msgstr "Default Client"

#: app/modules/web/themes/material-blue/views/config/general-auth.inc:91
msgid "Sets the default users group for newly created SSO users"
msgstr "Sets the default users group for newly created SSO users"
Expand Down
12 changes: 11 additions & 1 deletion app/modules/web/Controllers/Helpers/Account/AccountHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ final class AccountHelper extends HelperBase
* @var ItemPresetService
*/
private $itemPresetService;
/**
* @var UserGroupService
*/
private $userGroupService;
/**
* @var string
*/
Expand Down Expand Up @@ -218,6 +222,8 @@ public function setViewForAccount(AccountDetailsResponse $accountDetailsResponse
$this->view->assign('accountData', $accountData);
$this->view->assign('gotData', true);

$this->view->assign('accountClientId', $accountData->getClientId());

$accountActionsHelper = $this->dic->get(AccountActionsHelper::class);

$this->view->assign('accountActions', $accountActionsHelper->getActionsForAccount($this->accountAcl, $accountActionsDto));
Expand Down Expand Up @@ -403,6 +409,9 @@ public function setViewForBlank($actionId)
$this->view->assign('accountId', 0);
$this->view->assign('gotData', false);

$userGroupData = $this->userGroupService->getById($userData->getUserGroupId());
$this->view->assign('accountClientId', $userGroupData->getDefaultClientId());

$this->view->assign('accountActions',
$this->dic->get(AccountActionsHelper::class)
->getActionsForAccount($this->accountAcl, new AccountActionsDto($this->accountId)));
Expand Down Expand Up @@ -463,9 +472,10 @@ protected function initialize()
$this->accountHistoryService = $this->dic->get(AccountHistoryService::class);
$this->publicLinkService = $this->dic->get(PublicLinkService::class);
$this->itemPresetService = $this->dic->get(ItemPresetService::class);
$this->userGroupService = $this->dic->get(UserGroupService::class);

$this->view->assign('changesHash', '');
$this->view->assign('chkUserEdit', false);
$this->view->assign('chkGroupEdit', false);
}
}
}
5 changes: 5 additions & 0 deletions app/modules/web/Controllers/UserGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use SP\Repositories\NoSuchItemException;
use SP\Services\Auth\AuthException;
use SP\Services\ServiceException;
use SP\Services\Client\ClientService;
use SP\Services\User\UserService;
use SP\Services\UserGroup\UserGroupService;
use SP\Services\UserGroup\UserToUserGroupService;
Expand Down Expand Up @@ -159,6 +160,10 @@ protected function setViewData($userGroupId = null)

$this->view->assign('group', $userGroupData);

$clients = SelectItemAdapter::factory(ClientService::getItemsBasic())->getItemsFromModel();

$this->view->assign('clients', $clients);

$users = $userGroupData->getUsers() ?: [];

$this->view->assign('users',
Expand Down
1 change: 1 addition & 0 deletions app/modules/web/Forms/UserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected function analyzeRequestData()
$this->groupData->setId($this->itemId);
$this->groupData->setName($this->request->analyzeString('name'));
$this->groupData->setDescription($this->request->analyzeString('description'));
$this->groupData->setDefaultClientId($this->request->analyzeInt('default_client_id'));
$this->groupData->setUsers($this->request->analyzeArray('users', null, []));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use SP\Services\Account\AccountAcl;

$accountData = $_getvar('accountData');
$accountAcl = $_getvar('accountAcl');
$accountClientId = $_getvar('accountClientId');
$gotData = $_getvar('gotData', false);
$showLinked = $gotData && count($_getvar('linkedAccounts', [])) > 0;
$showFiles = $gotData && $configData->isFilesEnabled() && $accountAcl->isShowFiles();
Expand Down Expand Up @@ -128,7 +129,7 @@ $showCustomFields = count($_getvar('customFields', 0)) > 0;
foreach ($_getvar('clients') as $client): ?>
<option
value="<?php echo $client->getId(); ?>"
<?php echo ($gotData && $client->getId() === $accountData->getClientId())
<?php echo ($client->getId() === $accountClientId)
? 'selected'
: ''; ?>
>
Expand Down
23 changes: 23 additions & 0 deletions app/modules/web/themes/material-blue/views/itemshow/user_group.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ $group = $_getvar('group');
</td>
</tr>

<tr>
<td class="descField"><?php echo __('Default Client'); ?></td>
<td class="valField">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<select id="default_client_id" name="default_client_id"
class="select-box" <?php echo $_getvar('disabled'); ?>>
<option value=""><?php echo __('Select Client'); ?></option>
<?php /** @var SelectItem $client */
foreach ($_getvar('clients') as $client): ?>
<option
value="<?php echo $client->getId(); ?>"
<?php echo ($client->getId() === $group->getDefaultClientId())
? 'selected'
: ''; ?>
>
<?php echo htmlspecialchars($client->getName(), ENT_QUOTES); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</td>
</tr>

<tr>
<td class="descField"><?php echo __('Users'); ?></td>
<td class="valField">
Expand Down
20 changes: 20 additions & 0 deletions lib/SP/DataModel/UserGroupData.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class UserGroupData extends DataModelBase implements DataModelInterface
* @var string
*/
public $description;
/**
* @var int
*/
public $defaultClientId = 0;
/**
* @var array
*/
Expand Down Expand Up @@ -82,6 +86,14 @@ public function getDescription()
return $this->description;
}

/**
* @return int
*/
public function getDefaultClientId()
{
return (int)$this->defaultClientId;
}

/**
* @return array
*/
Expand Down Expand Up @@ -113,4 +125,12 @@ public function setDescription($description)
{
$this->description = $description;
}

/**
* @param int $defaultClientId
*/
public function setDefaultClientId($defaultClientId)
{
$this->defaultClientId = (int)$defaultClientId;
}
}
17 changes: 9 additions & 8 deletions lib/SP/Repositories/UserGroup/UserGroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function getById($id)
{
$queryData = new QueryData();
$queryData->setMapClassName(UserGroupData::class);
$queryData->setQuery('SELECT id, `name`, description FROM UserGroup WHERE id = ? LIMIT 1');
$queryData->setQuery('SELECT id, `name`, description, defaultClientId FROM UserGroup WHERE id = ? LIMIT 1');
$queryData->addParam($id);

return $this->db->doSelect($queryData);
Expand All @@ -187,7 +187,7 @@ public function getByName($name)
{
$queryData = new QueryData();
$queryData->setMapClassName(UserGroupData::class);
$queryData->setQuery('SELECT id, `name`, description FROM UserGroup WHERE name = ? LIMIT 1');
$queryData->setQuery('SELECT id, `name`, description, defaultClientId FROM UserGroup WHERE name = ? LIMIT 1');
$queryData->addParam($name);

return $this->db->doSelect($queryData);
Expand All @@ -204,7 +204,7 @@ public function getAll()
{
$queryData = new QueryData();
$queryData->setMapClassName(UserGroupData::class);
$queryData->setQuery('SELECT id, `name`, description FROM UserGroup ORDER BY name');
$queryData->setQuery('SELECT id, `name`, description, defaultClientId FROM UserGroup ORDER BY name');

return $this->db->doSelect($queryData);
}
Expand All @@ -225,7 +225,7 @@ public function getByIdBatch(array $ids)
}

$query = /** @lang SQL */
'SELECT id, name, description FROM UserGroup WHERE id IN (' . $this->getParamsFromArray($ids) . ')';
'SELECT id, name, description, defaultClientId FROM UserGroup WHERE id IN (' . $this->getParamsFromArray($ids) . ')';

$queryData = new QueryData();
$queryData->setMapClassName(UserGroupData::class);
Expand Down Expand Up @@ -270,7 +270,7 @@ public function search(ItemSearchData $itemSearchData)
{
$queryData = new QueryData();
$queryData->setMapClassName(UserGroupData::class);
$queryData->setSelect('id, name, description');
$queryData->setSelect('id, name, description, defaultClientId');
$queryData->setFrom('UserGroup');
$queryData->setOrder('name');

Expand Down Expand Up @@ -307,11 +307,11 @@ public function create($itemData)
}

$query = /** @lang SQL */
'INSERT INTO UserGroup SET `name` = ?, description = ?';
'INSERT INTO UserGroup SET `name` = ?, description = ?, defaultClientId = ?';

$queryData = new QueryData();
$queryData->setQuery($query);
$queryData->setParams([$itemData->getName(), $itemData->getDescription()]);
$queryData->setParams([$itemData->getName(), $itemData->getDescription(), $itemData->getDefaultClientId()]);
$queryData->setOnErrorMessage(__u('Error while creating the group'));

return $this->db->doQuery($queryData)->getLastId();
Expand Down Expand Up @@ -352,10 +352,11 @@ public function update($itemData)
}

$queryData = new QueryData();
$queryData->setQuery('UPDATE UserGroup SET `name` = ?, description = ? WHERE id = ? LIMIT 1');
$queryData->setQuery('UPDATE UserGroup SET `name` = ?, description = ?, defaultClientId = ? WHERE id = ? LIMIT 1');
$queryData->setParams([
$itemData->getName(),
$itemData->getDescription(),
$itemData->getDefaultClientId(),
$itemData->getId()
]);
$queryData->setOnErrorMessage(__u('Error while updating the group'));
Expand Down
7 changes: 4 additions & 3 deletions schemas/dbstructure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,10 @@ DROP TABLE IF EXISTS `UserGroup`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `UserGroup`
(
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`defaultClientId` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
Expand Down