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

DB page - role configuration, collaborators, roles #3762

Merged
merged 41 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0b6761a
Move database page contents into schema section within db page
pavish Aug 12, 2024
6f842c2
Implement Database model class
pavish Aug 12, 2024
62b03dd
Merge branch 'develop' of https://github.com/mathesar-foundation/math…
pavish Aug 12, 2024
63dd1cb
Reorganize items in databases directory
pavish Aug 15, 2024
126e27b
Update menu component styling
pavish Aug 15, 2024
15a0951
Use callbacks in Route utility components instead of events
pavish Aug 15, 2024
8133181
Add routes for all sections in database page
pavish Aug 15, 2024
278d101
Merge branch 'develop' of https://github.com/mathesar-foundation/math…
pavish Aug 15, 2024
a2981e0
Implement batching api requests
pavish Aug 16, 2024
805c6d0
Implement AsyncRpcApiStore
pavish Aug 16, 2024
52abcdb
Name model class files appropriately
pavish Aug 16, 2024
101eab7
Implement SortedImmutableMap
pavish Aug 16, 2024
44f8b95
Add roles rpc methods
pavish Aug 16, 2024
ebc9667
Add Role and ConfiguredRole models
pavish Aug 16, 2024
fd541a4
Add before run and on response calls to AsyncRpcApiStore's batch runner
pavish Aug 16, 2024
b5a0023
Add GridTable component
pavish Aug 16, 2024
c49cf79
Add database page settings content layout component
pavish Aug 16, 2024
df5495a
Add methods to fetch configured roles and roles from database model
pavish Aug 16, 2024
8e79ac0
Implement database settings context and basic RoleConfiguration page
pavish Aug 16, 2024
3509aab
Implement basic Roles page
pavish Aug 16, 2024
8ae3daa
Add collaborators api and model
pavish Aug 16, 2024
3b5a443
Implement Role Configuration page
pavish Aug 17, 2024
dbeae24
Implement base collaborator page
pavish Aug 17, 2024
77dbbf1
Display user and role information in collaborators page
pavish Aug 18, 2024
cd97e2d
Implement add collaborator modal
pavish Aug 18, 2024
f73beb1
Implement updating role for collaborator
pavish Aug 18, 2024
6cfe5df
Add help content to role selector, move configured role selector into…
pavish Aug 18, 2024
5c39e43
Implement delete action for collaborators
pavish Aug 18, 2024
b7a4529
Implement basic ui for create role modal, display child role names in…
pavish Aug 18, 2024
3566d3d
fix type errors
pavish Aug 18, 2024
07a9b7a
Add todo item for eslint rules to add
pavish Aug 18, 2024
a4f8c68
Merge branch 'develop' into db-page-1
pavish Aug 20, 2024
fde099b
Merge branch 'develop' of https://github.com/mathesar-foundation/math…
pavish Aug 22, 2024
efbe539
Add model functions in Role for setting members and deleting
pavish Aug 22, 2024
841ae42
Implement UI for setting role members and deleting role
pavish Aug 22, 2024
d7f14ae
Reset stores when items in dependent stores are deleted
pavish Aug 22, 2024
ad3d5fb
Make request for adding roles
pavish Aug 22, 2024
551b5f7
Use a store for configured_role_id property in Collaborator model
pavish Aug 22, 2024
4c32dc9
Improve names of model methods
pavish Aug 22, 2024
e760376
Temporarily hide Database permissions button and db actions
pavish Aug 22, 2024
6189c0e
Merge branch 'develop' of https://github.com/mathesar-foundation/math…
pavish Aug 22, 2024
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
8 changes: 6 additions & 2 deletions mathesar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@
path('shares/tables/<slug>/', views.shared_table, name='shared_table'),
path('shares/explorations/<slug>/', views.shared_query, name='shared_query'),
path('databases/', views.databases, name='databases'),
path('db/<database_id>/', views.schemas, name='schemas'),
path('i18n/', include('django.conf.urls.i18n')),
re_path(
r'^db/(?P<database_id>\w+)/(?P<schema_id>\w+)/',
r'^db/(?P<database_id>\w+)/schemas/(?P<schema_id>\w+)/',
views.schemas_home,
name='schema_home'
),
re_path(
r'^db/(?P<database_id>\w+)/((schemas|settings)/)?',
views.schemas,
name='schemas'
),
]
3 changes: 3 additions & 0 deletions mathesar_ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module.exports = {
'array-bracket-spacing': 'off',
'no-restricted-syntax': 0,
'@typescript-eslint/require-await': 'off',
// TODO_BETA: Add following eslint rules
// '@typescript-eslint/consistent-type-imports': 'error',
// 'no-duplicate-imports': 'error',
'class-methods-use-this': 'off',
'no-multiple-empty-lines': 1,
'import/order': [
Expand Down
18 changes: 9 additions & 9 deletions mathesar_ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
--color-text-muted: #6b7280;
--color-substring-match: rgb(254, 221, 72);
--color-substring-match-light: rgba(254, 221, 72, 0.2);
--text-size-xx-small: var(--size-xx-small); // 8px
--text-size-x-small: var(--size-x-small); // 10px
--text-size-small: var(--size-small); // 12px
--text-size-base: var(--size-base); // 14px
--text-size-large: var(--size-large); // 16px
--text-size-x-large: var(--size-x-large); // 18px
--text-size-xx-large: var(--size-xx-large); // 20px
--text-size-ultra-large: var(--size-ultra-large); // 24px
--text-size-super-ultra-large: var(--size-super-ultra-large); // 32px
--text-size-xx-small: var(--size-xx-small);
--text-size-x-small: var(--size-x-small);
--text-size-small: var(--size-small);
--text-size-base: var(--size-base);
--text-size-large: var(--size-large);
--text-size-x-large: var(--size-x-large);
--text-size-xx-large: var(--size-xx-large);
--text-size-ultra-large: var(--size-ultra-large);
--text-size-super-ultra-large: var(--size-super-ultra-large);

--modal-z-index: 50;
--modal-record-selector-z-index: 50;
Expand Down
41 changes: 41 additions & 0 deletions mathesar_ui/src/api/rpc/collaborators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

import type { RawConfiguredRole } from './configured_roles';
import type { RawDatabase } from './databases';

export interface RawCollaborator {
id: number;
user_id: number;
database_id: RawDatabase['id'];
configured_role_id: RawConfiguredRole['id'];
}

export const collaborators = {
list: rpcMethodTypeContainer<
{
database_id: RawDatabase['id'];
},
Array<RawCollaborator>
>(),
add: rpcMethodTypeContainer<
{
database_id: RawDatabase['id'];
user_id: number;
configured_role_id: RawConfiguredRole['id'];
},
RawCollaborator
>(),
set_role: rpcMethodTypeContainer<
{
collaborator_id: RawCollaborator['id'];
configured_role_id: RawConfiguredRole['id'];
},
RawCollaborator
>(),
delete: rpcMethodTypeContainer<
{
collaborator_id: RawCollaborator['id'];
},
void
>(),
};
20 changes: 10 additions & 10 deletions mathesar_ui/src/api/rpc/configured_roles.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

import type { Server } from './servers';
import type { RawServer } from './servers';

export interface ConfiguredRole {
export interface RawConfiguredRole {
id: number;
server_id: Server['id'];
server_id: RawServer['id'];
name: string;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const configured_roles = {
list: rpcMethodTypeContainer<
{
server_id: ConfiguredRole['server_id'];
server_id: RawConfiguredRole['server_id'];
},
Array<ConfiguredRole>
Array<RawConfiguredRole>
>(),

add: rpcMethodTypeContainer<
{
server_id: ConfiguredRole['server_id'];
name: ConfiguredRole['name'];
server_id: RawConfiguredRole['server_id'];
name: RawConfiguredRole['name'];
password: string;
},
ConfiguredRole
RawConfiguredRole
>(),

delete: rpcMethodTypeContainer<
{
configured_role_id: ConfiguredRole['id'];
configured_role_id: RawConfiguredRole['id'];
},
void
>(),

set_password: rpcMethodTypeContainer<
{
configured_role_id: ConfiguredRole['id'];
configured_role_id: RawConfiguredRole['id'];
password: string;
},
void
Expand Down
22 changes: 11 additions & 11 deletions mathesar_ui/src/api/rpc/database_setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

import type { ConfiguredRole } from './configured_roles';
import type { DatabaseResponse } from './databases';
import type { Server } from './servers';
import type { RawConfiguredRole } from './configured_roles';
import type { RawDatabase } from './databases';
import type { RawServer } from './servers';

export const sampleDataOptions = [
'library_management',
Expand All @@ -12,27 +12,27 @@ export const sampleDataOptions = [
export type SampleDataSchemaIdentifier = (typeof sampleDataOptions)[number];

export interface DatabaseConnectionResult {
server: Server;
database: DatabaseResponse;
configured_role: ConfiguredRole;
server: RawServer;
database: RawDatabase;
configured_role: RawConfiguredRole;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const database_setup = {
create_new: rpcMethodTypeContainer<
{
database: DatabaseResponse['name'];
database: RawDatabase['name'];
sample_data?: SampleDataSchemaIdentifier[];
},
DatabaseConnectionResult
>(),

connect_existing: rpcMethodTypeContainer<
{
host: Server['host'];
port: Server['port'];
database: DatabaseResponse['name'];
role: ConfiguredRole['name'];
host: RawServer['host'];
port: RawServer['port'];
database: RawDatabase['name'];
role: RawConfiguredRole['name'];
password: string;
sample_data?: SampleDataSchemaIdentifier[];
},
Expand Down
36 changes: 5 additions & 31 deletions mathesar_ui/src/api/rpc/databases.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

import type { Server } from './servers';
import type { RawServer } from './servers';

export interface DatabaseResponse {
export interface RawDatabase {
id: number;
name: string;
server_id: Server['id'];
}

/**
* TODO_BETA: Modify after store discussion is resolved
*/
export class Database implements DatabaseResponse {
readonly id: number;

readonly name: string;

readonly server_id: number;

readonly server_host: string;

readonly server_port: number;

constructor(databaseResponse: DatabaseResponse, server: Server) {
this.id = databaseResponse.id;
this.name = databaseResponse.name;
if (databaseResponse.server_id !== server.id) {
throw new Error('Server ids do not match');
}
this.server_id = databaseResponse.server_id;
this.server_host = server.host;
this.server_port = server.port;
}
server_id: RawServer['id'];
}

export const databases = {
list: rpcMethodTypeContainer<
{
server_id?: DatabaseResponse['server_id'];
server_id?: RawDatabase['server_id'];
},
Array<DatabaseResponse>
Array<RawDatabase>
>(),
};
4 changes: 4 additions & 0 deletions mathesar_ui/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import Cookies from 'js-cookie';

import { buildRpcApi } from '@mathesar/packages/json-rpc-client-builder';

import { collaborators } from './collaborators';
import { columns } from './columns';
import { configured_roles } from './configured_roles';
import { constraints } from './constraints';
import { database_setup } from './database_setup';
import { databases } from './databases';
import { records } from './records';
import { roles } from './roles';
import { schemas } from './schemas';
import { servers } from './servers';
import { tables } from './tables';
Expand All @@ -17,10 +19,12 @@ export const api = buildRpcApi({
endpoint: '/api/rpc/v0/',
getHeaders: () => ({ 'X-CSRFToken': Cookies.get('csrftoken') }),
methodTree: {
collaborators,
configured_roles,
database_setup,
databases,
records,
roles,
schemas,
servers,
tables,
Expand Down
56 changes: 56 additions & 0 deletions mathesar_ui/src/api/rpc/roles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

import type { RawDatabase } from './databases';

export interface RawRoleMember {
oid: number;
admin: boolean;
}

export interface RawRole {
oid: number;
name: string;
super: boolean;
inherits: boolean;
create_role: boolean;
create_db: boolean;
login: boolean;
description?: string;
members?: RawRoleMember[];
}

export const roles = {
list: rpcMethodTypeContainer<
{
database_id: RawDatabase['id'];
},
Array<RawRole>
>(),

add: rpcMethodTypeContainer<
{
database_id: RawDatabase['id'];
rolename: RawRole['name'];
login: boolean;
password?: string;
},
RawRole
>(),

set_members: rpcMethodTypeContainer<
{
database_id: RawDatabase['id'];
role_oid: RawRole['oid'];
members: RawRole['oid'][];
},
RawRole
>(),

delete: rpcMethodTypeContainer<
{
database_id: RawDatabase['id'];
role_oid: RawRole['oid'];
},
void
>(),
};
4 changes: 2 additions & 2 deletions mathesar_ui/src/api/rpc/servers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

export interface Server {
export interface RawServer {
id: number;
host: string;
port: number;
}

export const servers = {
list: rpcMethodTypeContainer<void, Array<Server>>(),
list: rpcMethodTypeContainer<void, Array<RawServer>>(),
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
--slate-700: #424952;
--slate-800: #25292e;

--sand-50: #fcfbf8;
--sand-100: #f9f8f6;
--sand-200: #efece7;
--sand-300: #e2dcd4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ImmutableMap<Key, Value> {
* know.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private getNewInstance(...args: any[]): this {
protected getNewInstance(...args: any[]): this {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any
return new (this.constructor as any)(...args) as this;
}
Expand Down Expand Up @@ -134,6 +134,12 @@ export default class ImmutableMap<Key, Value> {
);
}

mapKeys<NewKey>(fn: (value: Value) => NewKey): ImmutableMap<NewKey, Value> {
return new ImmutableMap(
[...this.values()].map((value) => [fn(value), value]),
);
}

filterValues(fn: (value: Value) => boolean): ImmutableMap<Key, Value> {
return new ImmutableMap(
[...this.entries()].filter(([, value]) => fn(value)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ImmutableMap from './ImmutableMap';

export default class SortedImmutableMap<Key, Value> extends ImmutableMap<
Key,
Value
> {
sortFn;

constructor(
sortFn: (j: Iterable<[Key, Value]>) => Iterable<[Key, Value]>,
i: Iterable<[Key, Value]> = [],
) {
const sorted = sortFn(i);
super(sorted);
this.sortFn = sortFn;
}

protected getNewInstance(...args: any[]): this {

Check warning on line 18 in mathesar_ui/src/component-library/common/utils/SortedImmutableMap.ts

View workflow job for this annotation

GitHub Actions / Run front end linter

Unexpected any. Specify a different type
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any
return new (this.constructor as any)(this.sortFn, ...args) as this;
}
}
Loading
Loading