Skip to content
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
1 change: 1 addition & 0 deletions lib/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private function getCapabilitiesStatus(bool $complete = false): array {
private function getCapabilitiesCircle(): array {
return [
'constants' => $this->getCapabilitiesCircleConstants(),
'membersListVisibility' => true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that needed

'config' => $this->getCapabilitiesCircleConfig()
];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public function link(string $emulated, string $circleId, string $singleId): Data
*/
private function setLocalFederatedUser(string $emulated): void {
$user = $this->userSession->getUser();
$this->federatedUserService->setCurrentPatron($user->getUID());
$this->federatedUserService->setLocalCurrentUserId($emulated);
$this->federatedUserService->setCurrentPatron($user->getUID());
}
}
1 change: 1 addition & 0 deletions lib/Controller/LocalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ public function link(string $circleId, string $singleId): DataResponse {
$this->setCurrentFederatedUser();

$this->permissionService->userMustBeMember($this->userSession->getUser()->getUID(), $circleId);
$this->memberService->assertCanViewMembers($circleId);

$membership = $this->membershipService->getMembership($circleId, $singleId, true);

Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public function inherited(string $circleId): DataResponse {
}

try {
$this->memberService->assertCanViewMembers($circleId);
$circle = $this->circleService->getCircle($circleId);

return new DataResponse($circle->getInheritedMembers());
Expand All @@ -334,6 +335,7 @@ public function memberships(string $circleId): DataResponse {
}

try {
$this->memberService->assertCanViewMembers($circleId);
$circle = $this->circleService->getCircle($circleId);

return new DataResponse($circle->getMemberships());
Expand Down
13 changes: 13 additions & 0 deletions lib/FederatedItems/CircleSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

use OCA\Circles\AuditLog\Operation;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Exceptions\FederatedItemBadRequestException;
use OCA\Circles\IFederatedItem;
use OCA\Circles\IFederatedItemAsyncProcess;
use OCA\Circles\IFederatedItemHighSeverity;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Federated\FederatedEvent;
use OCA\Circles\Model\Helpers\MemberHelper;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\AuditLogService;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Service\ShareTokenService;
Expand Down Expand Up @@ -48,6 +51,16 @@ public function verify(FederatedEvent $event): void {
$setting = $params->g('setting');
$value = $params->gBool('unset') ? null : $params->g('value');

if ($setting === Circle::SETTING_MEMBERS_VIEW_PERMISSION_LEVEL
&& $value !== null
&& !in_array($value, [
(string)Member::LEVEL_MEMBER,
(string)Member::LEVEL_MODERATOR,
(string)Member::LEVEL_ADMIN,
], true)) {
throw new FederatedItemBadRequestException('Invalid members visibility permission level');
}

$settings = $circle->getSettings();

if (!is_null($value)) {
Expand Down
24 changes: 21 additions & 3 deletions lib/Model/Circle.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Circle extends ManagedModel implements IEntity, IDeserializable, IQueryRow
// settings array keys
public const SETTING_EXTERNAL_ID = 'external_id';
public const SETTING_TEAM_FOLDER_QUOTA = 'team_folder_quota';
public const SETTING_MEMBERS_VIEW_PERMISSION_LEVEL = 'membersViewPermissionLevel';

/**
* Note: When editing those values, update lib/Application/Capabilities.php
Expand Down Expand Up @@ -687,6 +688,21 @@ public function getSettings(): array {
return $this->settings;
}

public function getMembersViewPermissionLevel(): int {
$level = $this->settings[self::SETTING_MEMBERS_VIEW_PERMISSION_LEVEL] ?? Member::LEVEL_MEMBER;

return match (is_int($level) ? (string)$level : $level) {
(string)Member::LEVEL_MEMBER => Member::LEVEL_MEMBER,
(string)Member::LEVEL_MODERATOR => Member::LEVEL_MODERATOR,
default => Member::LEVEL_ADMIN,
};
}

public function canViewMembers(): bool {
return $this->hasInitiator()
&& $this->getInitiator()->getLevel() >= $this->getMembersViewPermissionLevel();
}

/**
* @param string $description
*
Expand Down Expand Up @@ -840,21 +856,23 @@ public function jsonSerialize(): array {
'url' => $this->getUrl(),
'creation' => $this->getCreation(),
'initiator' => ($this->hasInitiator()) ? $this->getInitiator() : null,
'membersViewPermissionLevel' => $this->getMembersViewPermissionLevel(),
'canViewMembers' => $this->canViewMembers(),
];

if ($this->hasOwner()) {
$arr['owner'] = $this->getOwner();
}

if ($this->hasMembers()) {
if ($this->canViewMembers() && $this->hasMembers()) {
$arr['members'] = $this->getMembers();
}

if (!is_null($this->inheritedMembers)) {
if ($this->canViewMembers() && !is_null($this->inheritedMembers)) {
$arr['inheritedMembers'] = $this->getInheritedMembers();
}

if ($this->hasMemberships()) {
if ($this->canViewMembers() && $this->hasMemberships()) {
$arr['memberships'] = $this->getMemberships();
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Service/FederatedUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public function setLocalCurrentUser(?IUser $user): void {
* @throws SingleCircleNotFoundException
*/
public function setLocalCurrentUserId(string $userId): void {
$this->initiatedByAdmin = null;
$this->currentUser = $this->getLocalFederatedUser($userId);
}

Expand All @@ -206,6 +207,7 @@ public function setLocalCurrentUserId(string $userId): void {
* @throws SingleCircleNotFoundException
*/
public function setLocalCurrentApp(string $appId, int $appNumber): void {
$this->initiatedByAdmin = null;
$this->currentApp = $this->getAppInitiator($appId, $appNumber);
}

Expand All @@ -226,6 +228,7 @@ public function setCurrentUser(IFederatedUser $federatedUser): void {

$this->confirmFederatedUser($federatedUser);

$this->initiatedByAdmin = null;
$this->currentUser = $federatedUser;
}

Expand All @@ -234,6 +237,7 @@ public function setCurrentUser(IFederatedUser $federatedUser): void {
*/
public function unsetCurrentUser(): void {
$this->currentUser = null;
$this->initiatedByAdmin = null;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion lib/Service/MemberService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCA\Circles\Exceptions\FederatedUserException;
use OCA\Circles\Exceptions\InitiatorNotConfirmedException;
use OCA\Circles\Exceptions\InitiatorNotFoundException;
use OCA\Circles\Exceptions\InsufficientPermissionException;
use OCA\Circles\Exceptions\InvalidIdException;
use OCA\Circles\Exceptions\MemberNotFoundException;
use OCA\Circles\Exceptions\OwnerNotFoundException;
Expand Down Expand Up @@ -132,7 +133,7 @@ public function getMemberById(
* @throws RequestBuilderException
*/
public function getMembers(string $circleId, bool $fullDetails = false, int $limit = 0, string $search = '', ?int $role = null): array {
$this->federatedUserService->mustHaveCurrentUser();
$this->assertCanViewMembers($circleId);

$probe = new MemberProbe();
if ($this->federatedUserService->hasRemoteInstance()) {
Expand All @@ -152,6 +153,20 @@ public function getMembers(string $circleId, bool $fullDetails = false, int $lim
);
}

public function assertCanViewMembers(string $circleId): void {
$this->federatedUserService->mustHaveCurrentUser();
if ($this->federatedUserService->canBypassCurrentUserCondition()
|| $this->federatedUserService->isInitiatedByAdmin()
|| ($this->federatedUserService->hasRemoteInstance() && !$this->federatedUserService->hasCurrentEntity())) {
return;
}

$circle = $this->circleRequest->getCircle($circleId, $this->federatedUserService->getCurrentEntity());
if (!$circle->canViewMembers()) {
throw new InsufficientPermissionException('You do not have permission to view the members of this team');
}
}

/**
* @param string $circleId
* @param FederatedUser $federatedUser
Expand Down
16 changes: 13 additions & 3 deletions src/teams/components/TeamHeader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/

import type Circle from '../team-page/models/circle.ts'
import type { Team } from '../types.ts'

import { shallowMount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { nextTick } from 'vue'
import TeamHeader from './TeamHeader.vue'
import { useTeamsStore } from '../store.ts'

Expand All @@ -21,7 +23,7 @@ vi.mock('vue-router', () => ({
useRouter: () => ({ push: vi.fn() }),
}))
vi.mock('vuex', () => ({
useStore: () => ({ getters: { getCircle: () => undefined } }),
useStore: () => ({ getters: { getCircle: () => ({ members: { alice: { singleId: 'alice' } } }) } }),
}))
vi.mock('../api.ts', () => ({ fetchTeams: vi.fn(async () => []) }))

Expand All @@ -30,7 +32,7 @@ vi.mock('../api.ts', () => ({ fetchTeams: vi.fn(async () => []) }))
*
* @param canCreateTeam - value served for the `canCreateTeam` initial state
*/
function mountHeader(canCreateTeam: boolean) {
function mountHeader(canCreateTeam: boolean, canViewMembers = true) {
loadState.mockImplementation((app, key, fallback) => {
if (app === 'circles' && key === 'canCreateTeam') {
return canCreateTeam
Expand All @@ -42,7 +44,7 @@ function mountHeader(canCreateTeam: boolean) {

const wrapper = shallowMount(TeamHeader, {
props: {
circle: { id: 'team-1', displayName: 'Marketing' } as Circle,
circle: { id: 'team-1', displayName: 'Marketing', canViewMembers } as Circle,
},
global: {
plugins: [pinia],
Expand Down Expand Up @@ -91,4 +93,12 @@ describe('TeamHeader team creation', () => {

expect(findNewTeamButton(wrapper)).toBeUndefined()
})

it.each([true, false])('respects member visibility %s in both header previews', async (canViewMembers) => {
const { wrapper, store } = mountHeader(false, canViewMembers)
store.teams = [{ id: 'team-1' } as Team]
await nextTick()

expect(wrapper.findAllComponents({ name: 'TeamMembersRow' })).toHaveLength(canViewMembers ? 2 : 0)
})
})
4 changes: 3 additions & 1 deletion src/teams/components/TeamHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const team = computed(() => teamsStore.getTeam(props.circle.id))

const { canLeave, canDelete, onCopyLink, onLeave, onDelete } = useTeamActions(() => team.value)

const members = computed<Member[]>(() => Object.values(store.getters.getCircle(props.circle.id)?.members ?? {}))
const members = computed<Member[]>(() => props.circle.canViewMembers
? Object.values(store.getters.getCircle(props.circle.id)?.members ?? {})
: [])

// Members row: show as many 24px avatars as fit the measured width of the
// (always mounted) trigger row, and collapse the rest into a "+n" label.
Expand Down
94 changes: 94 additions & 0 deletions src/teams/components/TeamMembersVisibilitySettings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*!
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { showError, showSuccess } from '@nextcloud/dialogs'
import { flushPromises, shallowMount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import NcRadioGroup from '@nextcloud/vue/components/NcRadioGroup'
import NcRadioGroupButton from '@nextcloud/vue/components/NcRadioGroupButton'
import TeamMembersVisibilitySettings from './TeamMembersVisibilitySettings.vue'
import Circle from '../team-page/models/circle.ts'

const dispatch = vi.hoisted(() => vi.fn())
vi.mock('vuex', () => ({ useStore: () => ({ dispatch }) }))
vi.mock('@nextcloud/dialogs', () => ({ showError: vi.fn(), showSuccess: vi.fn() }))

function mountSettings(level = 8, permission?: string) {
return shallowMount(TeamMembersVisibilitySettings, {
props: {
circle: new Circle({
id: 'team',
owner: { id: 'owner', level: 9 },
initiator: { id: 'actor', level },
settings: permission ? { membersViewPermissionLevel: permission } : {},
}),
},
global: { renderStubDefaultSlot: true },
})
}

describe('Member visibility setting', () => {
beforeEach(() => {
vi.clearAllMocks()
dispatch.mockResolvedValue(undefined)
})

it('defaults to all members and offers the three role thresholds', () => {
const wrapper = mountSettings()

expect(wrapper.getComponent(NcRadioGroup).props('modelValue')).toBe('1')
expect(wrapper.findAllComponents(NcRadioGroupButton).map((button) => button.props('value'))).toEqual(['8', '4', '1'])
})

it.each(['1', '4', '8'])('loads saved threshold %s', (permission) => {
expect(mountSettings(8, permission).getComponent(NcRadioGroup).props('modelValue')).toBe(permission)
})

it.each([8, 9])('lets role %s save a new threshold', async (level) => {
const wrapper = mountSettings(level)
wrapper.getComponent(NcRadioGroup).vm.$emit('update:modelValue', '4')
await flushPromises()

expect(dispatch).toHaveBeenCalledWith('editCircleSetting', {
circleId: 'team',
setting: { setting: 'membersViewPermissionLevel', value: '4' },
})
expect(showSuccess).toHaveBeenCalled()
})

it('keeps the persisted selection and displays an error on failure', async () => {
dispatch.mockRejectedValue(new Error('Failed'))
const wrapper = mountSettings(8, '4')
wrapper.getComponent(NcRadioGroup).vm.$emit('update:modelValue', '8')
await flushPromises()

expect(wrapper.getComponent(NcRadioGroup).props('modelValue')).toBe('4')
expect(wrapper.getComponent(NcRadioGroup).attributes('disabled')).toBe('false')
expect(showError).toHaveBeenCalled()
expect(showSuccess).not.toHaveBeenCalled()
})

it('prevents duplicate saves while a request is pending', async () => {
dispatch.mockReturnValue(new Promise(() => {}))
const wrapper = mountSettings()
const group = wrapper.getComponent(NcRadioGroup)
group.vm.$emit('update:modelValue', '4')
group.vm.$emit('update:modelValue', '8')
await wrapper.vm.$nextTick()

expect(dispatch).toHaveBeenCalledTimes(1)
expect(group.attributes('disabled')).toBe('true')
})

it.each([1, 4])('does not allow role %s to change visibility', async (level) => {
const wrapper = mountSettings(level)
const group = wrapper.getComponent(NcRadioGroup)
group.vm.$emit('update:modelValue', '8')
await flushPromises()

expect(group.attributes('disabled')).toBe('true')
expect(dispatch).not.toHaveBeenCalled()
})
})
Loading
Loading