Skip to content
Draft
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
5 changes: 2 additions & 3 deletions packages/backend/src/models/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ export class MiChannel {
})
public isLocalOnly: boolean;

@Column({
...id(),
array: true, default: '{}',
@Column('varchar', {
array: true, length: 64, default: '{}',
comment: 'Collaborator user IDs.',
})
public collaboratorIds: MiUser['id'][];
Expand Down
22 changes: 13 additions & 9 deletions packages/backend/src/server/api/endpoints/channels/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
banner = null;
}

let validatedCollaboratorIds: string[] | undefined = undefined;
if (ps.collaboratorIds !== undefined) {
if (channel.userId !== me.id && !iAmModerator) {
throw new ApiError(meta.errors.accessDenied);
}
const users = await this.usersRepository.findBy({
id: In(ps.collaboratorIds),
});
if (users.length !== ps.collaboratorIds.length) {
throw new ApiError({
message: 'One or more collaborator user IDs are invalid.',
code: 'INVALID_COLLABORATOR_USER_IDS',
id: '3e7c9a2b-4f8c-4d1e-9b7a-3f6e8c7d9a1b',
if (ps.collaboratorIds.length > 0) {
const users = await this.usersRepository.findBy({
id: In(ps.collaboratorIds),
});
if (users.length !== ps.collaboratorIds.length) {
throw new ApiError({
message: 'One or more collaborator user IDs are invalid.',
code: 'INVALID_COLLABORATOR_USER_IDS',
id: '3e7c9a2b-4f8c-4d1e-9b7a-3f6e8c7d9a1b',
});
}
}
await this.channelService.setCollaborators(channel, ps.collaboratorIds);
validatedCollaboratorIds = ps.collaboratorIds;
}

if (ps.isLocalOnly !== undefined) channel.isLocalOnly = ps.isLocalOnly;
Expand All @@ -153,6 +156,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
...(typeof ps.allowRenoteToExternal === 'boolean' ? { allowRenoteToExternal: ps.allowRenoteToExternal } : {}),
...(ps.isLocalOnly !== undefined ? { isLocalOnly: ps.isLocalOnly } : {}),
...(ps.transferAdminUserId !== undefined && channel.userId === ps.transferAdminUserId ? { userId: ps.transferAdminUserId } : {}),
...(validatedCollaboratorIds !== undefined ? { collaboratorIds: validatedCollaboratorIds } : {}),
});

return await this.channelEntityService.pack(channel.id, me);
Expand Down
59 changes: 44 additions & 15 deletions packages/frontend/src/pages/channel-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder v-if="isRoot">
<template #label>{{ i18n.ts._channel.dangerSettings }}</template>

<MkButton style="margin: 16px" danger @click="transferAdmin()">
<MkButton v-if="isOwner" style="margin: 16px" danger @click="transferAdmin()">
{{ i18n.ts._channel.transferAdminConfirmTitle }}
</MkButton>
<MkButton v-if="channelId" style="margin: 16px" danger @click="archive()"><i class="ti ti-trash"></i> {{ i18n.ts.archive }}</MkButton>
Expand Down Expand Up @@ -133,6 +133,7 @@ const allowRenoteToExternal = ref(true);
const isLocalOnly = ref(false);
const pinnedNoteIds = ref<Misskey.entities.Note['id'][]>([]);
const isRoot = ref(false);
const isOwner = ref(false);
const collaboratorUsers = ref<Misskey.entities.User[]>([]);

watch(() => bannerId.value, async () => {
Expand Down Expand Up @@ -172,6 +173,7 @@ async function fetchChannel() {
collaboratorUsers.value = [];
}
isRoot.value = ($i && $i.id === result.userId) || iAmModerator;
isOwner.value = $i !== null && $i.id === result.userId;

channel.value = result;
}
Expand Down Expand Up @@ -244,26 +246,29 @@ function collaboratorUserDelete(i: number) {
}

function save() {
const params = {
name: name.value,
description: description.value,
bannerId: bannerId.value,
color: color.value,
isSensitive: isSensitive.value,
allowRenoteToExternal: allowRenoteToExternal.value,
isLocalOnly: isLocalOnly.value,
collaboratorIds: collaboratorUsers.value.map(x => x.id),
} satisfies Misskey.entities.ChannelsCreateRequest;

if (props.channelId != null) {
os.apiWithDialog('channels/update', {
...params,
channelId: props.channelId,
name: name.value,
description: description.value,
bannerId: bannerId.value,
color: color.value,
isSensitive: isSensitive.value,
allowRenoteToExternal: allowRenoteToExternal.value,
isLocalOnly: isLocalOnly.value,
pinnedNoteIds: pinnedNoteIds.value,
collaboratorIds: collaboratorUsers.value.map(x => x.id),
...(isRoot.value ? { collaboratorIds: collaboratorUsers.value.map(x => x.id) } : {}),
});
} else {
os.apiWithDialog('channels/create', params).then(created => {
os.apiWithDialog('channels/create', {
name: name.value,
description: description.value,
bannerId: bannerId.value,
color: color.value,
isSensitive: isSensitive.value,
allowRenoteToExternal: allowRenoteToExternal.value,
isLocalOnly: isLocalOnly.value,
}).then(created => {
router.push('/channels/:channelId', {
params: {
channelId: created.id,
Expand Down Expand Up @@ -342,4 +347,28 @@ definePage(() => ({
margin: 0 8px;
opacity: 0.5;
}

.userItem {
padding: 4px 0;
}

.userItemMain {
display: flex;
}

.userItemMainBody {
flex: 1;
min-width: 0;
margin-right: 8px;

&:hover {
text-decoration: none;
}
}

.unassign {
width: 32px;
height: 32px;
align-self: center;
}
</style>
38 changes: 37 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.