Skip to content

Commit 1f9df60

Browse files
committed
Fix for permission updates of a score lib entry
Signed-off-by: Mike Lischke <mike@lischke-online.de>
1 parent 00b1417 commit 1f9df60

2 files changed

Lines changed: 8 additions & 30 deletions

File tree

src/core/DatabaseTypes.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*/
55

6+
import type { ISbDmPermissionInfo } from "./ScoreBookDataModel.js";
7+
68
/**
79
* Types used for database entries.
810
*/
@@ -15,22 +17,13 @@ export interface ISoundLibFsNode {
1517
children?: ISoundLibFsNode[];
1618
}
1719

18-
/** Permission summary for the current user on a score or folder, as returned by the backend. */
19-
export interface IPermissionDBEntry {
20-
isOwner: boolean;
21-
canRead: boolean;
22-
canWrite: boolean;
23-
isWorld: boolean;
24-
groupIds: number[];
25-
}
26-
2720
/** Structure of a score lib folder entry as returned by the REST endpoint. */
2821
export interface IScoreLibFolderDBEntry {
2922
id: number;
3023
parentid: number;
3124
name: string;
3225
hasChildren: boolean;
33-
perm: IPermissionDBEntry;
26+
perm: ISbDmPermissionInfo;
3427
}
3528

3629
/** Structure of a score lib snippet entry as returned by the REST endpoint. */
@@ -39,7 +32,7 @@ export interface IScoreLibScoreDBEntry {
3932
folderid: number;
4033
name: string;
4134
content: string;
42-
perm: IPermissionDBEntry;
35+
perm: ISbDmPermissionInfo;
4336
}
4437

4538
/** Structure of an entry returned by the folder list API. */

src/core/ScoreBookDataModel.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export interface ISbDmVisual extends ISbDmCommon {
343343
getChildren?(): ScoreBookDataModelEntry[];
344344

345345
/** Permission info for the current user (undefined until the backend provides it). */
346-
readonly perm?: ISbDmPermissionInfo;
346+
perm?: ISbDmPermissionInfo;
347347
}
348348

349349
/** Permission summary for the current user on a score or folder. */
@@ -624,21 +624,6 @@ interface IWhoamiResponse {
624624
capabilities: ICapabilities;
625625
}
626626

627-
/**
628-
* Copies permission fields from a source into a target perm object in-place.
629-
*
630-
* @param target The existing perm to update.
631-
* @param source The new perm values to copy.
632-
*/
633-
const applyPerm = (target: ISbDmPermissionInfo, source: ISbDmPermissionInfo): void => {
634-
const t = target as Mutable<ISbDmPermissionInfo>;
635-
t.isOwner = source.isOwner;
636-
t.canRead = source.canRead;
637-
t.canWrite = source.canWrite;
638-
t.isWorld = source.isWorld;
639-
t.groupIds = source.groupIds;
640-
};
641-
642627
export class ScoreBookDataModel {
643628
/**
644629
* Indicates whether the current session is allowed to mutate scores on the backend.
@@ -1726,10 +1711,10 @@ export class ScoreBookDataModel {
17261711
const newList: Array<ISbDmScoreFolder | ISbDmScore> = [];
17271712

17281713
data.folders.forEach((folder) => {
1729-
const existing = existingById.get(folder.id) as ISbDmScoreFolder | undefined;
1714+
const existing = existingById.get(folder.id);
17301715
if (existing) {
17311716
existing.name = folder.name;
1732-
applyPerm(existing.perm!, folder.perm);
1717+
existing.perm = folder.perm;
17331718
newList.push(existing);
17341719

17351720
return;
@@ -1768,7 +1753,7 @@ export class ScoreBookDataModel {
17681753
if (existing) {
17691754
existing.name = score.name;
17701755
existing.content = score.content;
1771-
applyPerm(existing.perm!, score.perm);
1756+
existing.perm = score.perm;
17721757
newList.push(existing);
17731758

17741759
return;

0 commit comments

Comments
 (0)