@@ -600,7 +600,8 @@
|
||||
|
||||
<ChannelModal
|
||||
bind:show={showCreateChannel}
|
||||
onSubmit={async ({ type, name, is_private, access_control, group_ids, user_ids }) => {
|
||||
onSubmit={async (payload: any) => {
|
||||
let { type, name, is_private, access_grants, group_ids, user_ids } = payload ?? {};
|
||||
name = name?.trim();
|
||||
|
||||
if (type === 'dm') {
|
||||
@@ -619,7 +620,7 @@
|
||||
type: type,
|
||||
name: name,
|
||||
is_private: is_private,
|
||||
access_control: access_control,
|
||||
access_grants: access_grants,
|
||||
group_ids: group_ids,
|
||||
user_ids: user_ids
|
||||
}).catch((error) => {
|
||||
|
||||
@@ -25,6 +25,25 @@
|
||||
let showEditChannelModal = false;
|
||||
|
||||
let itemElement;
|
||||
|
||||
const hasPublicReadGrant = (grants: any) =>
|
||||
Array.isArray(grants) &&
|
||||
grants.some(
|
||||
(grant) =>
|
||||
grant?.principal_type === 'user' &&
|
||||
grant?.principal_id === '*' &&
|
||||
grant?.permission === 'read'
|
||||
);
|
||||
|
||||
const isPublicChannel = (channel: any): boolean => {
|
||||
if (channel?.type === 'group') {
|
||||
if (typeof channel?.is_private === 'boolean') {
|
||||
return !channel.is_private;
|
||||
}
|
||||
return hasPublicReadGrant(channel?.access_grants);
|
||||
}
|
||||
return hasPublicReadGrant(channel?.access_grants);
|
||||
};
|
||||
</script>
|
||||
|
||||
<ChannelModal
|
||||
@@ -32,11 +51,12 @@
|
||||
{channel}
|
||||
edit={true}
|
||||
{onUpdate}
|
||||
onSubmit={async ({ name, is_private, access_control, group_ids, user_ids }) => {
|
||||
onSubmit={async (payload: any) => {
|
||||
const { name, is_private, access_grants, group_ids, user_ids } = payload ?? {};
|
||||
const res = await updateChannelById(localStorage.token, channel.id, {
|
||||
name,
|
||||
is_private,
|
||||
access_control,
|
||||
access_grants,
|
||||
group_ids,
|
||||
user_ids
|
||||
}).catch((error) => {
|
||||
@@ -123,7 +143,7 @@
|
||||
{/if}
|
||||
{:else}
|
||||
<div class=" size-4 justify-center flex items-center ml-1">
|
||||
{#if channel?.type === 'group' ? !channel?.is_private : channel?.access_control === null}
|
||||
{#if isPublicChannel(channel)}
|
||||
<Hashtag className="size-3.5" strokeWidth="2.5" />
|
||||
{:else}
|
||||
<Lock className="size-[15px]" strokeWidth="2" />
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
export let onSubmit: Function = () => {};
|
||||
export let onUpdate: Function = () => {};
|
||||
|
||||
export let channel = null;
|
||||
export let channel: any = null;
|
||||
export let edit = false;
|
||||
|
||||
let channelTypes = ['group', 'dm'];
|
||||
@@ -31,7 +31,7 @@
|
||||
let name = '';
|
||||
|
||||
let isPrivate = null;
|
||||
let accessControl = {};
|
||||
let accessGrants = [];
|
||||
|
||||
let groupIds = [];
|
||||
let userIds = [];
|
||||
@@ -65,8 +65,8 @@
|
||||
await onSubmit({
|
||||
type: type,
|
||||
name: name.replace(/\s/g, '-'),
|
||||
is_private: type === 'group' ? isPrivate : null,
|
||||
access_control: type === '' ? accessControl : {},
|
||||
is_private: type === 'group' ? (isPrivate ?? true) : null,
|
||||
access_grants: type === '' ? accessGrants : [],
|
||||
group_ids: groupIds,
|
||||
user_ids: userIds
|
||||
});
|
||||
@@ -85,8 +85,12 @@
|
||||
|
||||
if (channel) {
|
||||
name = channel?.name ?? '';
|
||||
isPrivate = channel?.is_private ?? null;
|
||||
accessControl = channel.access_control;
|
||||
if (type === 'group') {
|
||||
isPrivate = typeof channel?.is_private === 'boolean' ? channel.is_private : true;
|
||||
} else {
|
||||
isPrivate = null;
|
||||
}
|
||||
accessGrants = channel?.access_grants ?? [];
|
||||
userIds = channel?.user_ids ?? [];
|
||||
}
|
||||
};
|
||||
@@ -102,8 +106,14 @@
|
||||
|
||||
const deleteHandler = async () => {
|
||||
showDeleteConfirmDialog = false;
|
||||
if (!channel?.id) {
|
||||
show = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await deleteChannelById(localStorage.token, channel.id).catch((error) => {
|
||||
const channelId = channel.id;
|
||||
|
||||
const res = await deleteChannelById(localStorage.token, channelId).catch((error) => {
|
||||
toast.error(error.message);
|
||||
});
|
||||
|
||||
@@ -111,7 +121,7 @@
|
||||
toast.success($i18n.t('Channel deleted successfully'));
|
||||
onUpdate();
|
||||
|
||||
if ($page.url.pathname === `/channels/${channel.id}`) {
|
||||
if ($page.url.pathname === `/channels/${channelId}`) {
|
||||
goto('/');
|
||||
}
|
||||
}
|
||||
@@ -122,7 +132,7 @@
|
||||
const resetHandler = () => {
|
||||
type = '';
|
||||
name = '';
|
||||
accessControl = {};
|
||||
accessGrants = [];
|
||||
userIds = [];
|
||||
loading = false;
|
||||
};
|
||||
@@ -226,11 +236,11 @@
|
||||
{#if type !== 'dm'}
|
||||
<div class="-mx-2 mb-1 mt-2.5 px-2">
|
||||
{#if type === ''}
|
||||
<AccessControl bind:accessControl accessRoles={['read', 'write']} />
|
||||
<AccessControl bind:accessGrants accessRoles={['read', 'write']} />
|
||||
{:else if type === 'group'}
|
||||
<Visibility
|
||||
state={isPrivate ? 'private' : 'public'}
|
||||
onChange={(value) => {
|
||||
onChange={(value: string) => {
|
||||
if (value === 'private') {
|
||||
isPrivate = true;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user