Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cmd K not working for viewer roles #8411

Merged
merged 5 commits into from
May 17, 2024
Merged
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
14 changes: 3 additions & 11 deletions packages/nc-gui/composables/useCommandPalette/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,11 @@ export const useCommandPalette = createSharedComposable(() => {
}
}
} else {
if (route.value.path.startsWith('/account')) {
if (activeScope.value.scope === 'account_settings') return
if (activeScope.value.scope === 'root') return

activeScope.value = { scope: 'account_settings', data: {} }
activeScope.value = { scope: 'root', data: {} }

loadScope()
} else {
if (activeScope.value.scope === 'root') return

activeScope.value = { scope: 'root', data: {} }

loadScope()
}
loadScope()
}
},
{ immediate: true, deep: true },
Expand Down
136 changes: 57 additions & 79 deletions packages/nocodb/src/services/command-palette.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { type UserType, ViewTypes } from 'nocodb-sdk';
import { Base } from '~/models';
import { BaseUser } from '~/models';
import { TablesService } from '~/services/tables.service';
import { deserializeJSON } from '~/utils/serialize';

Expand All @@ -20,95 +20,73 @@ export class CommandPaletteService {
async commandPalette(param: { body: any; user: UserType }) {
const cmdData = [];
try {
const { scope } = param.body;
const allBases = [];

if (scope === 'root') {
const bases = await Base.list({ user: param.user });
const bases = await BaseUser.getProjectsList(param.user.id, param);

for (const base of bases) {
cmdData.push({
id: `p-${base.id}`,
title: base.title,
icon: 'project',
iconColor: deserializeJSON(base.meta)?.iconColor,
section: 'Bases',
scopePayload: {
scope: `p-${base.id}`,
data: {
base_id: base.id,
},
},
});
}
} else if (scope.startsWith('p-')) {
const allBases = [];

const bases = await Base.list({ user: param.user });
allBases.push(...bases);
mertmit marked this conversation as resolved.
Show resolved Hide resolved

allBases.push(...bases);
const viewList = [];

const viewList = [];

for (const base of bases) {
viewList.push(
...(
(await this.tablesService.xcVisibilityMetaGet(
base.id,
null,
false,
)) as any[]
).filter((v) => {
return Object.keys(param.user.roles).some(
(role) => param.user.roles[role] && !v.disabled[role],
);
}),
);
}
for (const base of bases) {
viewList.push(
...(
(await this.tablesService.xcVisibilityMetaGet(
base.id,
null,
false,
)) as any[]
).filter((v) => {
return Object.keys(param.user.roles).some(
(role) => param.user.roles[role] && !v.disabled[role],
);
}),
);
}

const tableList = [];
const vwList = [];
const tableList = [];
const vwList = [];

for (const b of allBases) {
cmdData.push({
id: `p-${b.id}`,
title: b.title,
icon: 'project',
iconColor: deserializeJSON(b.meta)?.iconColor,
section: 'Bases',
});
}
for (const b of allBases) {
cmdData.push({
id: `p-${b.id}`,
title: b.title,
icon: 'project',
iconColor: deserializeJSON(b.meta)?.iconColor,
section: 'Bases',
});
}

for (const v of viewList) {
if (!tableList.find((el) => el.id === `tbl-${v.fk_model_id}`)) {
tableList.push({
id: `tbl-${v.fk_model_id}`,
title: v._ptn,
parent: `p-${v.base_id}`,
icon: v?.table_meta?.icon || v.ptype,
projectName: bases.find((el) => el.id === v.base_id)?.title,
section: 'Tables',
});
}
vwList.push({
id: `vw-${v.id}`,
title: `${v.title}`,
parent: `tbl-${v.fk_model_id}`,
icon: v?.meta?.icon || viewTypeAlias[v.type] || 'table',
for (const v of viewList) {
if (!tableList.find((el) => el.id === `tbl-${v.fk_model_id}`)) {
tableList.push({
id: `tbl-${v.fk_model_id}`,
title: v._ptn,
parent: `p-${v.base_id}`,
icon: v?.table_meta?.icon || v.ptype,
projectName: bases.find((el) => el.id === v.base_id)?.title,
section: 'Views',
is_default: v?.is_default,
handler: {
type: 'navigate',
payload: `/nc/${v.base_id}/${v.fk_model_id}/${encodeURIComponent(
v.id,
)}`,
},
section: 'Tables',
});
}

cmdData.push(...tableList);
cmdData.push(...vwList);
vwList.push({
id: `vw-${v.id}`,
title: `${v.title}`,
parent: `tbl-${v.fk_model_id}`,
icon: v?.meta?.icon || viewTypeAlias[v.type] || 'table',
projectName: bases.find((el) => el.id === v.base_id)?.title,
section: 'Views',
is_default: v?.is_default,
handler: {
type: 'navigate',
payload: `/nc/${v.base_id}/${v.fk_model_id}/${encodeURIComponent(
v.id,
)}`,
},
});
}

cmdData.push(...tableList);
cmdData.push(...vwList);
DarkPhoenix2704 marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
console.log(e);
return [];
Expand Down
1 change: 0 additions & 1 deletion packages/nocodb/src/services/org-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class OrgUsersService {

return await User.update(param.userId, {
...updateBody,
token_version: randomTokenString(),
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/nocodb/src/utils/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ const rolePermissions:
baseList: true,
testConnection: true,
isPluginActive: true,
commandPalette: true,
},
},
[OrgUserRoles.CREATOR]: {
Expand Down
Loading