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

Added new option in share with users in roles #17129

Open
wants to merge 1 commit into
base: developer
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion app/Fields/Owner.php
Expand Up @@ -81,8 +81,14 @@ public function getAccessibleGroups($private = '', $fieldType = false, $translat
$cacheKey = $private . $this->moduleName . $fieldType . $this->currentUser->getRole();
if (!\App\Cache::has('getAccessibleGroups', $cacheKey)) {
$currentUserRoleModel = \Settings_Roles_Record_Model::getInstanceById($this->currentUser->getRole());
if (!empty($fieldType) && (5 === (int) $currentUserRoleModel->get('sharedOwner' === $fieldType ? 'assignedmultiowner' : 'allowassignedrecordsto')) && 'Public' !== $private) {
$assignValue = (int) $currentUserRoleModel->get('sharedOwner' === $fieldType ? 'assignedmultiowner' : 'allowassignedrecordsto');
if (!empty($fieldType) && 5 === $assignValue && 'Public' !== $private) {
$accessibleGroups = $this->getAllocation('groups', $private, $fieldType);
} elseif (!empty($fieldType) && 6 === $assignValue && 'Public' !== $private) {
$accessibleGroups = $this->getGroups(false, 'private');
foreach (\App\User::getCurrentUserModel()->get('leader') as $groupId) {
$accessibleGroups[$groupId] = self::getGroupName($groupId);
}
} else {
$accessibleGroups = $this->getGroups(false, $private);
}
Expand Down Expand Up @@ -130,6 +136,8 @@ public function getAccessibleUsers($private = '', $fieldType = false)
$accessibleUser[$this->currentUser->getId()] = $this->currentUser->getName();
} elseif (!empty($fieldType) && 5 === $assignTypeValue) {
$accessibleUser = $this->getAllocation('users', '', $fieldType);
} elseif (!empty($fieldType) && 6 === $assignTypeValue) {
$accessibleUser = $this->getUsersInTheSameGroup();
} else {
$accessibleUser[$this->currentUser->getId()] = $this->currentUser->getName();
}
Expand All @@ -138,6 +146,37 @@ public function getAccessibleUsers($private = '', $fieldType = false)
return \App\Cache::get('getAccessibleUsers', $cacheKey);
}

/**
* Get users in the same group as currently logged user. Including users where user is a team leader.
*
* @return array
*/
public function getUsersInTheSameGroup(): array
{
$accessibleUsers = [];
$queryGenerator = (new \App\QueryGenerator('Users'))
->setFields(['id'])
->addCondition('status', 'Active', 'e');
$columnName = $queryGenerator->getColumnName('id');
$condition = ['or'];
$accessibleGroups = $this->getGroups(false, 'private');
foreach (array_keys($accessibleGroups) as $groupId) {
$condition[] = [$columnName => (new \App\Db\Query())->select(['userid'])->from(["condition_Groups_{$groupId}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $groupId)])];
}
foreach (\App\User::getCurrentUserModel()->get('leader') as $groupId) {
$condition[] = [$columnName => (new \App\Db\Query())->select(['userid'])->from(["condition_Groups_{$groupId}_" . \App\Layout::getUniqueId() => \App\PrivilegeUtil::getQueryToUsersByGroup((int) $groupId)])];
}
if (1 === \count($condition)) {
$condition = [$columnName => 0];
}
$queryGenerator->addNativeCondition($condition);
$dataReader = $queryGenerator->createQuery()->createCommand()->query();
while ($row = $dataReader->read()) {
$accessibleUsers[$row['id']] = self::getUserLabel($row['id']);
}
return $accessibleUsers;
}

/**
* Get accessible.
*
Expand Down
3 changes: 2 additions & 1 deletion languages/en-US/Settings/Roles.json
Expand Up @@ -48,7 +48,8 @@
"LBL_UPLOAD_LOGO": "Upload logo",
"LBL_UPLOAD_ERROR": "Error during upload",
"LBL_UPLOAD_SUCCESS": "Uploaded successfully",
"LBL_MULTI_COMPANY": "Organizational structure"
"LBL_MULTI_COMPANY": "Organizational structure",
"LBL_USERS_AND_GROUPS_RELATED_TO_LOGGED_IN_USER": "Users and groups who belong to the same group as the logged in user"
},
"js": {
"JS_NO_PERMISSIONS_TO_MOVE": "No permissions to move",
Expand Down
13 changes: 8 additions & 5 deletions layouts/basic/modules/Settings/Roles/EditView.tpl
Expand Up @@ -83,17 +83,20 @@
<label class="col-md-4"><strong>{\App\Language::translate('LBL_CAN_ASSIGN_MULTIOWNER_TO', $QUALIFIED_MODULE)}
: </strong></label>
<div class="col-md-7 fieldValue">
{assign var="ASSIGNED_MULTIOWNER" value=$RECORD_MODEL->get('assignedmultiowner')}
<select id="assignedmultiowner" class="row select2 form-control" name="assignedmultiowner">
<option value="1"
{if $RECORD_MODEL->get('assignedmultiowner') == '1'}selected="true" {/if}>{\App\Language::translate('LBL_ALL_USERS', $QUALIFIED_MODULE)}</option>
{if $ASSIGNED_MULTIOWNER == '1'}selected="true" {/if}>{\App\Language::translate('LBL_ALL_USERS', $QUALIFIED_MODULE)}</option>
<option value="2"
{if $RECORD_MODEL->get('assignedmultiowner') == '2'}selected="true" {/if}>{\App\Language::translate('LBL_USERS_WITH_SAME_OR_LOWER_LEVEL', $QUALIFIED_MODULE)}</option>
{if $ASSIGNED_MULTIOWNER == '2'}selected="true" {/if}>{\App\Language::translate('LBL_USERS_WITH_SAME_OR_LOWER_LEVEL', $QUALIFIED_MODULE)}</option>
<option value="3"
{if $RECORD_MODEL->get('assignedmultiowner') == '3'}selected="true" {/if}>{\App\Language::translate('LBL_USERS_WITH_LOWER_LEVEL', $QUALIFIED_MODULE)}</option>
{if $ASSIGNED_MULTIOWNER == '3'}selected="true" {/if}>{\App\Language::translate('LBL_USERS_WITH_LOWER_LEVEL', $QUALIFIED_MODULE)}</option>
<option value="4"
{if $RECORD_MODEL->get('assignedmultiowner') == '4'}selected="true" {/if}>{\App\Language::translate('LBL_JUST_ME', $QUALIFIED_MODULE)}</option>
{if $ASSIGNED_MULTIOWNER == '4'}selected="true" {/if}>{\App\Language::translate('LBL_JUST_ME', $QUALIFIED_MODULE)}</option>
<option value="5"
{if $RECORD_MODEL->get('assignedmultiowner') == '5'}selected="true" {/if}>{\App\Language::translate('LBL_FROM_PANEL', $QUALIFIED_MODULE)}</option>
{if $ASSIGNED_MULTIOWNER == '5'}selected="true" {/if}>{\App\Language::translate('LBL_FROM_PANEL', $QUALIFIED_MODULE)}</option>
<option value="6"
{if $ASSIGNED_MULTIOWNER == '6'}selected="true" {/if}>{\App\Language::translate('LBL_USERS_AND_GROUPS_RELATED_TO_LOGGED_IN_USER', $QUALIFIED_MODULE)}</option>
</select>
</div>
</div>
Expand Down