Skip to content

Commit

Permalink
Merge pull request #3689 from mathesar-foundation/homepage_fe
Browse files Browse the repository at this point in the history
Remove existing permissions logic on the frontend
  • Loading branch information
pavish authored Jul 23, 2024
2 parents 3a9e51c + 0f0caa0 commit 3f1e2f8
Show file tree
Hide file tree
Showing 52 changed files with 249 additions and 1,645 deletions.
54 changes: 0 additions & 54 deletions mathesar_ui/src/api/rest/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Schema } from '@mathesar/api/rpc/schemas';
import type { Database } from '@mathesar/AppTypes';
import type { Language } from '@mathesar/i18n/languages/utils';

import {
Expand All @@ -18,25 +16,9 @@ export interface UnsavedUser {
display_language: Language;
}

export type UserRole = 'viewer' | 'editor' | 'manager';

export interface DatabaseRole {
id: number;
database: Database['id'];
role: UserRole;
}

export interface SchemaRole {
id: number;
schema: Schema['oid'];
role: UserRole;
}

export interface User extends Omit<UnsavedUser, 'password'> {
readonly id: number;
readonly is_superuser: boolean;
readonly database_roles: DatabaseRole[];
readonly schema_roles: SchemaRole[];
}

function list() {
Expand Down Expand Up @@ -75,38 +57,6 @@ function resetPassword(userId: User['id'], password: string) {
});
}

function addDatabaseRole(
userId: User['id'],
databaseId: Database['id'],
role: UserRole,
) {
return postAPI<DatabaseRole>('/api/ui/v0/database_roles/', {
user: userId,
database: databaseId,
role,
});
}

function deleteDatabaseRole(roleId: DatabaseRole['id']) {
return deleteAPI(`/api/ui/v0/database_roles/${roleId}/`);
}

function addSchemaRole(
userId: User['id'],
schemaId: Schema['oid'],
role: UserRole,
) {
return postAPI<SchemaRole>('/api/ui/v0/schema_roles/', {
user: userId,
schema: schemaId,
role,
});
}

function deleteSchemaRole(roleId: SchemaRole['id']) {
return deleteAPI(`/api/ui/v0/schema_roles/${roleId}/`);
}

export default {
list,
get,
Expand All @@ -115,8 +65,4 @@ export default {
update,
changePassword,
resetPassword,
addDatabaseRole,
deleteDatabaseRole,
addSchemaRole,
deleteSchemaRole,
};
24 changes: 9 additions & 15 deletions mathesar_ui/src/components/AppHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
$: database = $currentDatabase;
$: schema = $currentSchema;
$: canExecuteDDL = $userProfile?.hasPermission(
{ database, schema },
'canExecuteDDL',
);
$: upgradable = $releaseDataStore?.value?.upgradeStatus === 'upgradable';
$: isNormalRoutingContext = commonData.routing_context === 'normal';
Expand Down Expand Up @@ -84,17 +80,15 @@
<span class="icon"><Icon {...iconShortcuts} /></span>
<span class="text">{$_('shortcuts')}</span>
</span>
{#if canExecuteDDL}
<ButtonMenuItem icon={iconAddNew} on:click={handleCreateEmptyTable}>
{$_('new_table_from_scratch')}
</ButtonMenuItem>
<LinkMenuItem
icon={iconAddNew}
href={getImportPageUrl(database.id, schema.oid)}
>
{$_('new_table_from_data_import')}
</LinkMenuItem>
{/if}
<ButtonMenuItem icon={iconAddNew} on:click={handleCreateEmptyTable}>
{$_('new_table_from_scratch')}
</ButtonMenuItem>
<LinkMenuItem
icon={iconAddNew}
href={getImportPageUrl(database.id, schema.oid)}
>
{$_('new_table_from_data_import')}
</LinkMenuItem>
<LinkMenuItem
icon={iconExploration}
href={getDataExplorerPageUrl(database.id, schema.oid)}
Expand Down
1 change: 0 additions & 1 deletion mathesar_ui/src/i18n/languages/en/dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@
"loading_release_data": "Loading release data",
"loading_spinner_no_progress_bar": "You will see a loading spinner but no progress bar.",
"log_out": "Log Out",
"manage_access": "Manage Access",
"manage_connections": "Manage Connections",
"manage_database_access": "Manage [databaseName] Database Access",
"manage_schema_access": "Manage [databaseName] Schema Access",
Expand Down
7 changes: 0 additions & 7 deletions mathesar_ui/src/pages/data-explorer/DataExplorerPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
getExplorationPageUrl,
getSchemaPageUrl,
} from '@mathesar/routes/urls';
import { getUserProfileStoreFromContext } from '@mathesar/stores/userProfile';
import { DataExplorer } from '@mathesar/systems/data-explorer';
import type { QueryManager } from '@mathesar/systems/data-explorer/types';
const userProfile = getUserProfileStoreFromContext();
export let database: Database;
export let schema: Schema;
export let queryManager: QueryManager;
$: ({ query } = queryManager);
$: canEditMetadata =
$userProfile?.hasPermission({ database, schema }, 'canEditMetadata') ??
false;
function gotoSchemaPage() {
router.goto(getSchemaPageUrl(database.id, schema.oid));
Expand All @@ -43,7 +37,6 @@
<LayoutWithHeader fitViewport>
<DataExplorer
{queryManager}
{canEditMetadata}
on:close={gotoExplorationPage}
on:delete={gotoSchemaPage}
/>
Expand Down
117 changes: 44 additions & 73 deletions mathesar_ui/src/pages/database/DatabaseDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
iconDatabase,
iconDeleteMajor,
iconEdit,
iconManageAccess,
iconMoreActions,
iconRefresh,
} from '@mathesar/icons';
Expand Down Expand Up @@ -42,12 +41,10 @@
} from '@mathesar-component-library';
import AddEditSchemaModal from './AddEditSchemaModal.svelte';
import DbAccessControlModal from './DbAccessControlModal.svelte';
import SchemaListSkeleton from './SchemaListSkeleton.svelte';
import SchemaRow from './SchemaRow.svelte';
const addEditModal = modal.spawnModalController();
const accessControlModal = modal.spawnModalController();
const editConnectionModal = modal.spawnModalController();
const deleteConnectionModal = modal.spawnModalController();
Expand All @@ -59,12 +56,6 @@
$: schemasMap = $schemasStore.data;
$: schemasRequestStatus = $schemasStore.requestStatus;
$: canExecuteDDL = userProfile?.hasPermission({ database }, 'canExecuteDDL');
$: canEditPermissions = userProfile?.hasPermission(
{ database },
'canEditPermissions',
);
let filterQuery = '';
let targetSchema: Schema | undefined;
let isReflectionRunning = false;
Expand Down Expand Up @@ -107,10 +98,6 @@
});
}
function manageAccess() {
accessControlModal.open();
}
function handleClearFilterQuery() {
filterQuery = '';
}
Expand All @@ -136,58 +123,50 @@
}}
>
<svelte:fragment slot="action">
{#if canExecuteDDL || canEditPermissions}
<div>
{#if canEditPermissions}
<Button on:click={manageAccess} appearance="secondary">
<Icon {...iconManageAccess} />
<span>{$_('manage_access')}</span>
</Button>
{/if}
<DropdownMenu
showArrow={false}
triggerAppearance="plain"
label=""
closeOnInnerClick={false}
icon={iconMoreActions}
preferredPlacement="bottom-end"
menuStyle="--spacing-y:0.8em;"
<div>
<DropdownMenu
showArrow={false}
triggerAppearance="plain"
label=""
closeOnInnerClick={false}
icon={iconMoreActions}
preferredPlacement="bottom-end"
menuStyle="--spacing-y:0.8em;"
>
<ButtonMenuItem
icon={{ ...iconRefresh, spin: isReflectionRunning }}
disabled={isReflectionRunning}
on:click={reflect}
>
<div class="reflect">
{$_('sync_external_changes')}
<Help>
<p>
{$_('sync_external_changes_structure_help')}
</p>
<p>
{$_('sync_external_changes_data_help')}
</p>
</Help>
</div>
</ButtonMenuItem>
{#if userProfile?.isSuperUser}
<ButtonMenuItem
icon={{ ...iconRefresh, spin: isReflectionRunning }}
disabled={isReflectionRunning}
on:click={reflect}
icon={iconEdit}
on:click={() => editConnectionModal.open()}
>
<div class="reflect">
{$_('sync_external_changes')}
<Help>
<p>
{$_('sync_external_changes_structure_help')}
</p>
<p>
{$_('sync_external_changes_data_help')}
</p>
</Help>
</div>
{$_('edit_connection')}
</ButtonMenuItem>
{#if userProfile?.isSuperUser}
<ButtonMenuItem
icon={iconEdit}
on:click={() => editConnectionModal.open()}
>
{$_('edit_connection')}
</ButtonMenuItem>
<ButtonMenuItem
icon={iconDeleteMajor}
danger
on:click={() => deleteConnectionModal.open()}
>
{$_('delete_connection')}
</ButtonMenuItem>
{/if}
</DropdownMenu>
</div>
{/if}
<ButtonMenuItem
icon={iconDeleteMajor}
danger
on:click={() => deleteConnectionModal.open()}
>
{$_('delete_connection')}
</ButtonMenuItem>
{/if}
</DropdownMenu>
</div>
</svelte:fragment>
</AppSecondaryHeader>

Expand All @@ -201,12 +180,10 @@
on:clear={handleClearFilterQuery}
>
<svelte:fragment slot="action">
{#if canExecuteDDL}
<Button on:click={addSchema} appearance="primary">
<Icon {...iconAddNew} />
<span>{$_('create_schema')}</span>
</Button>
{/if}
<Button on:click={addSchema} appearance="primary">
<Icon {...iconAddNew} />
<span>{$_('create_schema')}</span>
</Button>
</svelte:fragment>
<p slot="resultInfo">
<RichText
Expand All @@ -227,10 +204,6 @@
<SchemaRow
{database}
{schema}
canExecuteDDL={userProfile?.hasPermission(
{ database, schema },
'canExecuteDDL',
)}
on:edit={() => editSchema(schema)}
on:delete={() => deleteSchema(schema)}
/>
Expand All @@ -255,8 +228,6 @@
schema={targetSchema}
/>

<DbAccessControlModal controller={accessControlModal} {database} />

<EditConnectionModal controller={editConnectionModal} connection={database} />
<DeleteConnectionModal
controller={deleteConnectionModal}
Expand Down
Loading

0 comments on commit 3f1e2f8

Please sign in to comment.