Repository navigation
Conversation
98a0144 to
eef90dd
Compare
| * @return list<CollectiveShare> | ||
| */ | ||
| public function getSharesByCollective(string $userId, Collective $collective): array { | ||
| $collectiveShares = $collective->canShare() |
There was a problem hiding this comment.
Security: canShare() only compares the member level with the collective's share level, and with the default permissions every member can share. So every member now receives the tokens of all other members' working links, which weakens two existing controls:
- Removing a member no longer ends their link access. Checked on 35.0.2: bob (member) got the collective owner's token from
GET …/collectives/1/shares. After bob was removed from the collective, his own link is dead (Circle not found), but the owner's token still serves the collective through the public API. Revoking a removed member's access now means rotating every member's links, editable ones included. - Users who are not allowed to create public links (
shareapi_allow_links_exclude_groups, enforced increateShare()viashareApiAllowLinks()) still get the Sharing tab with "Copy public link" and "Generate QR code" for everybody else's links.
Suggestion: only return other members' tokens to collective admins, who can delete those links anyway, and list other members' shares without the token/URL for everybody else (or don't list them).
| // memberCanEdit() only depends on the collective permissions, not on the user that loaded the collective | ||
| $collective ??= $this->collectiveMapper->findByIdAndUser($collectiveShare->getCollectiveId(), $collectiveShare->getOwner()); |
There was a problem hiding this comment.
findByIdAndUser($collectiveId, $owner) didn't only provide memberCanEdit(): it returned null when the share owner is no longer a member, which made the share non-editable. With the requesting user's collective, shares of former members are now listed to every sharing member as working links with "Can edit".
Reproduced on 35.0.2: bob makes his link editable and is then removed from the collective. GET …/collectives/1/shares as admin or moderator returns bob's share with editable: true, the sidebar lists it with copy and QR actions, but the public API answers 404 Circle not found for that token. Only admins can delete it.
So the comment isn't accurate for this case. Either keep the owner-membership check for shares of other users, or don't list (or mark as dead) shares whose owner left.
| ? t('collectives', '{label} (by {initiator})', { label, initiator }, { escape: false }) | ||
| : t('collectives', 'Share link (by {initiator})', { initiator }, { escape: false }) |
There was a problem hiding this comment.
escape: false alone isn't enough: t() from @nextcloud/l10n still runs the result through DOMPurify (sanitize defaults to true), which re-serializes the string as soon as it contains a <. As the title is rendered as text, entities then show up literally and tag-like parts disappear. With the display name Alice O'Brien & <Co> the entry is titled Share link (by Alice O'Brien & ) (checked on 35.0.2); a label like Q&A <draft> would end up as Q&A (by …). Own shares are fine now since they return the raw label.
| ? t('collectives', '{label} (by {initiator})', { label, initiator }, { escape: false }) | |
| : t('collectives', 'Share link (by {initiator})', { initiator }, { escape: false }) | |
| ? t('collectives', '{label} (by {initiator})', { label, initiator }, { escape: false, sanitize: false }) | |
| : t('collectives', 'Share link (by {initiator})', { initiator }, { escape: false, sanitize: false }) |
| <SharingEntryLink | ||
| v-for="share in otherShares" |
There was a problem hiding this comment.
The entries of other members get no index, so unlabeled links of the same member all get the same title, and like the own entries each one has the same button names. Checked on 35.0.2 as a member, with two unlabeled links of alice and two other links: two entries titled Share link (by Alice …), and the tab contains "Copy public link to clipboard" 4× and "Share actions" 4×, with nothing tying a button to its entry.
Screen-reader users (and, for identical titles, everyone) can't tell which link they copy, or as an admin which one they unshare. Suggestion: number unlabeled links per owner (or show the creation/expiration date), and include the entry title in the accessible names, e.g. Share actions for {title}.
| */ | ||
| public function getSharesByCollective(string $userId, Collective $collective): array { | ||
| $collectiveShares = $collective->canShare() | ||
| ? $this->collectiveShareMapper->findByCollectiveId($collective->getId()) |
There was a problem hiding this comment.
Performance: this endpoint isn't only used by the Sharing tab. CollectiveContainer.initCollective() calls getShares() whenever a member opens a collective, and with the default permissions every member can share. Each of these requests now loops over the shares of all members and pages, with a getShareByToken() per share (share query plus userExists($token) and owner checks) and a display name lookup. The whole list, including every member's tokens, is then kept in each member's localStorage.
Also, findByCollectiveId() filters on collective_id, which has no index on oc_collectives_shares (only owner and token; EXPLAIN shows a full table scan on 35.0.2), whereas the old per-user query could use the owner index.
Suggestion: load other members' shares lazily when the Sharing tab is opened (or per page), and add an index on collective_id (and page_id).
| try { | ||
| $share = $this->collectiveShareMapper->findOneByCollectiveIdAndToken($collective->getId(), $pageId, $token); | ||
| } catch (DoesNotExistException|MultipleObjectsReturnedException $e) { | ||
| throw new NotFoundException($this->l10n->t('Share not found'), 0, $e); | ||
| } | ||
|
|
||
| if ($share->getOwner() !== $userId) { |
There was a problem hiding this comment.
canUpdateShare() (owner && canShare && canEdit) drives the canUpdate flag, while updateShare() enforces the same rule separately (the canShare/canEdit checks above plus this owner check). deleteShare() uses canDeleteShare() for both, so if (!$this->canUpdateShare($share, $collective, $userId)) here would keep the UI flag and the API in sync.
The lookup and its error mapping are also duplicated with deleteShare(), with different contracts: update answers a translated Share not found (404) and lets a DB error through (500), delete answers an untranslated Failed to find collective share <token> (404) and maps a DB error to 403. A shared private lookup helper would align them.
| <NcActionSeparator v-if="currentCollective.canShare || share.canDelete" /> | ||
|
|
||
| <NcActionButton class="new-share-link" @click.prevent.stop="onNewShare"> | ||
| <NcActionButton v-if="currentCollective.canShare" class="new-share-link" @click.prevent.stop="onNewShare"> |
There was a problem hiding this comment.
currentCollective.canShare is always true inside this component: the Sharing tab is only mounted with v-if="!isPublic && currentCollectiveCanShare" (PageSidebar.vue). So these guards, and :forceMenu (QR code and "Add another link" are always there), never change anything.
Conversely, members without share permission never see this tab, so the canDelete: true the backend now returns for their old links (asserted in testGetSharesByCollectiveWithoutSharePermission) has no UI. Checked on 35.0.2 with the share level set to moderators: a member gets her old link with canDelete: true from the API, but her sidebar only has Attachments, Backlinks and Versions. Either drop the guards, or change the tab condition if non-sharers should be able to remove their old links.
| protected string $password = ''; | ||
| protected ?\DateTime $expirationDate = null; | ||
| protected string $label = ''; | ||
| /** transient attributes, only set for users that manage shares */ |
There was a problem hiding this comment.
These are set for every requesting user, not only for users that manage shares: setUserAttributes() also runs in the non-sharer branch of getSharesByCollective() and after create/update. They only stay at their defaults for findShare()/findShareByToken().
| /** transient attributes, only set for users that manage shares */ | |
| /** transient attributes, set for the requesting user when shares are listed, created or updated */ |
| // Admin can still create an own share link | ||
| await expect(sharingTab.getByRole('button', { name: 'Create a new share link' })).toBeVisible() | ||
|
|
||
| const entry = pageSidebar.getShareEntry(sharingTab, `Share link (by ${account.userId})`) |
There was a problem hiding this comment.
Low / optional (test coverage): both new e2e tests match titles via account.userId / user.account.userId, but the UI renders ownerDisplayName || owner. The test users' display names equal their user ids, so a regression in the display-name fallback (or the escaping issue in SharingEntryLink.vue) can't fail these tests. A test user with a distinct display name, or a small Vitest test for the title computation, would cover it. The new frontend logic in SharingEntryLink.vue/SidebarTabSharing.vue (own vs. other shares, isOwnShare) has no Vitest coverage either.
| await expect(memberPage.getByRole('menuitem', { name: 'Customize link' })).toHaveCount(0) | ||
| await expect(memberPage.getByRole('menuitem', { name: 'Add another link' })).toBeVisible() | ||
| await expect(memberPage.getByRole('menuitem', { name: 'Unshare' })).toHaveCount(0) | ||
| await memberPage.close() |
There was a problem hiding this comment.
Cosmetic (tests): memberPage.close() only runs when every assertion above passed; a failing expect leaks the second browser context for the rest of the worker. A try { … } finally { await memberPage.close() } (or a fixture that owns the member page) keeps cleanup unconditional. Same pattern at line 135, though there the window is only createShare().
| * @param actionName Name of the menu action | ||
| * @param entry The share entry, defaults to the only entry in the sharing tab | ||
| */ | ||
| public async clickShareMenuAction(sharingTab: Locator, actionName: string, entry: Locator = sharingTab.locator('.sharing-entry')): Promise<void> { |
There was a problem hiding this comment.
Cosmetic (tests): no caller passes the new entry argument (all calls use the default), and the new tests call openShareMenu(entry) directly instead. The parameter and its docblock line could be dropped to keep the signature as before.
| }, | ||
|
|
||
| ownShares() { | ||
| return this.shares.filter((share) => share.owner === getCurrentUser()?.uid) |
There was a problem hiding this comment.
Cosmetic (clean code): the "is this my share" test share.owner === getCurrentUser()?.uid is now written three times (here, the negated filter below, and isOwnShare in SharingEntryLink.vue). Computing it once, e.g. an isOwn flag from the backend (which already knows the requesting user) or a small shared helper, keeps the three from drifting apart.
- Only users with sharing permissions can see others' shares. - Admins can only delete others' shares, not edit them. Fixes: #2329 Signed-off-by: Jonas <jonas@freesources.org> Assisted-by: ClaudeCode:claude-opus-5-5
eef90dd to
6236504
Compare
|
I found this use case particularly interesting for experimenting with user journeys across different personas and permission levels, with accessibility checks integrated into each journey. I've put together an experimental run covering collective- and page-level sharing scenarios: Journey results
Each journey includes step-by-step states, functional checks, and accessibility checks, including keyboard-only testing and axe accessibility reports. This is still a work in progress, especially around making the accessibility checks more useful and relevant to actual user workflows. Not suggesting this needs to be part of the PR itself, but I'd be interested in any feedback or ideas on how to improve these checks so they better fit your requirements and testing workflows. Update: @mejo- here is a check log itself https://github.com/openuji/journey-checks/actions/runs/44478505056/job/135404803274#step:8:301 |
Fixes: #2329
Assisted-by: ClaudeCode:claude-opus-5-5
🖼️ Screenshots
🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)🤖 AI (if applicable)