Skip to content

Commit 4ea377d

Browse files
committed
fix(sharing): properly frame block list
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 2efe48b commit 4ea377d

3 files changed

Lines changed: 25 additions & 47 deletions

File tree

apps/settings/src/components/AdminSettingsSharingForm.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@
115115
value="yes"
116116
type="radio"
117117
@update:modelValue="onUpdateExcludeGroups">
118-
{{ t('settings', 'Exclude some groups') }}
118+
{{ t('settings', 'Exclude some groups (block list)') }}
119119
</NcCheckboxRadioSwitch>
120120
<NcCheckboxRadioSwitch
121121
v-model="settings.excludeGroups"
122122
name="excludeGroups"
123123
value="allow"
124124
type="radio"
125125
@update:modelValue="onUpdateExcludeGroups">
126-
{{ t('settings', 'Allow some groups') }}
126+
{{ t('settings', 'Allow some groups only (allow list)') }}
127127
</NcCheckboxRadioSwitch>
128128
<div v-show="settings.excludeGroups !== 'no'" class="sharing__labeled-entry sharing__input">
129129
<NcSettingsSelectGroup
@@ -133,7 +133,15 @@
133133
:label="settings.excludeGroups === 'allow' ? t('settings', 'Groups allowed to share') : t('settings', 'Groups excluded from sharing')"
134134
:disabled="settings.excludeGroups === 'no'"
135135
style="width: 100%" />
136-
<em id="settings-sharing-excluded-groups-desc">{{ t('settings', 'Not allowed groups will still be able to receive shares, but not to initiate them.') }}</em>
136+
<em id="settings-sharing-excluded-groups-desc">
137+
<template v-if="settings.excludeGroups === 'allow'">
138+
{{ t('settings', 'Only members of at least one of this groups will be able to initiate shares.') }}
139+
{{ t('settings', 'Others will be blocked, but are still able to receive shares.') }}
140+
</template>
141+
<template v-else>
142+
{{ t('settings', 'A member of at least least one of this groups will not be able to initiate new shares, but will still be able to receive shares.') }}
143+
</template>
144+
</em>
137145
</div>
138146
</div>
139147

lib/private/Contacts/ContactsMenu/ContactsStore.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OC\KnownUser\KnownUserService;
1111
use OC\Profile\ProfileManager;
12+
use OC\Share20\ShareDisableChecker;
1213
use OCA\UserStatus\Db\UserStatus;
1314
use OCA\UserStatus\Service\StatusService;
1415
use OCP\Contacts\ContactsMenu\IContactsStore;
@@ -38,6 +39,7 @@ public function __construct(
3839
private IGroupManager $groupManager,
3940
private KnownUserService $knownUserService,
4041
private IL10NFactory $l10nFactory,
42+
private ShareDisableChecker $shareDisableChecker,
4143
) {
4244
}
4345

@@ -173,31 +175,11 @@ private function filterContacts(
173175
$excludeGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no');
174176

175177
// whether to filter out local users
176-
$skipLocal = false;
178+
$skipLocal = $this->shareDisableChecker->sharingDisabledForUser($self->getUID());
177179
// whether to filter out all users which don't have a common group as the current user
178180
$ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
179181

180182
$selfGroups = $this->groupManager->getUserGroupIds($self);
181-
182-
if ($excludeGroups && $excludeGroups !== 'no') {
183-
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
184-
$decodedExcludeGroups = json_decode($excludedGroups, true);
185-
$excludeGroupsList = $decodedExcludeGroups ?? [];
186-
187-
if ($excludeGroups !== 'allow') {
188-
if (count($selfGroups) > 0 && count(array_diff($selfGroups, $excludeGroupsList)) === 0) {
189-
// all the groups of the current user are excluded -> filter all local users
190-
$skipLocal = true;
191-
}
192-
} else {
193-
$skipLocal = true;
194-
if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
195-
// a group of the current user is allowed -> do not filter all local users
196-
$skipLocal = false;
197-
}
198-
}
199-
}
200-
201183
// ownGroupsOnly : some groups may be excluded
202184
if ($ownGroupsOnly) {
203185
$excludeGroupsFromOwnGroups = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', '');

lib/private/Share20/ShareDisableChecker.php

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,17 @@ public function sharingDisabledForUser(?string $userId): bool {
5050
return false;
5151
}
5252
$usersGroups = $this->groupManager->getUserGroupIds($user);
53-
if ($excludeGroups !== 'allow') {
54-
if (!empty($usersGroups)) {
55-
$remainingGroups = array_diff($usersGroups, $excludedGroups);
56-
// if the user is only in groups which are disabled for sharing then
57-
// sharing is also disabled for the user
58-
if (empty($remainingGroups)) {
59-
$this->sharingDisabledForUsersCache[$userId] = true;
60-
return true;
61-
}
62-
}
63-
} else {
64-
if (!empty($usersGroups)) {
65-
$remainingGroups = array_intersect($usersGroups, $excludedGroups);
66-
// if the user is in any group which is allowed for sharing then
67-
// sharing is also allowed for the user
68-
if (!empty($remainingGroups)) {
69-
$this->sharingDisabledForUsersCache[$userId] = false;
70-
return false;
71-
}
72-
}
73-
$this->sharingDisabledForUsersCache[$userId] = true;
74-
return true;
75-
}
53+
$intersectingGroups = array_intersect($usersGroups, $excludedGroups);
54+
55+
// 1. If the user is in a group which is disabled for sharing then
56+
// sharing is also disabled for the user.
57+
// 2. If the user is in a group which is allowed for sharing then
58+
// sharing is also allowed for the user.
59+
$isInList = $intersectingGroups !== [];
60+
$isBlockList = $excludeGroups !== 'allow';
61+
$sharingDisabled = $isBlockList ? $isInList : !$isInList;
62+
$this->sharingDisabledForUsersCache[$userId] = $sharingDisabled;
63+
return $sharingDisabled;
7664
}
7765

7866
$this->sharingDisabledForUsersCache[$userId] = false;

0 commit comments

Comments
 (0)