-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from DashHub-ai/feature/add-users-groups
Add users groups
- Loading branch information
Showing
172 changed files
with
4,039 additions
and
344 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './user-organization-info-form-field'; | ||
export * from './user-organization-settings-form-field'; | ||
export * from './user-update-auth-methods-form-field'; |
39 changes: 0 additions & 39 deletions
39
apps/admin/src/modules/users/form/update/fields/user-organization-info-form-field.tsx
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
apps/admin/src/modules/users/form/update/fields/user-organization-settings-form-field.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
controlled, | ||
useFormValidatorMessages, | ||
type ValidationErrorsListProps, | ||
} from '@under-control/forms'; | ||
|
||
import type { SdkTableRowWithIdNameT, SdkUpdateUserOrganizationInputT } from '@llm/sdk'; | ||
|
||
import { FormField } from '@llm/ui'; | ||
import { useI18n } from '~/i18n'; | ||
import { OrganizationsSearchSelect, UserOrganizationRoleSelect } from '~/modules/organizations'; | ||
|
||
type Props = ValidationErrorsListProps<SdkUpdateUserOrganizationInputT> & { | ||
organization: SdkTableRowWithIdNameT; | ||
}; | ||
|
||
export const UserOrganizationSettingsFormField = controlled<SdkUpdateUserOrganizationInputT, Props>(( | ||
{ | ||
organization, | ||
errors, | ||
control: { bind }, | ||
}, | ||
) => { | ||
const t = useI18n().pack.modules.users.form.fields.organization; | ||
const validation = useFormValidatorMessages({ errors }); | ||
|
||
return ( | ||
<> | ||
<FormField | ||
className="uk-margin" | ||
label={t.choose.label} | ||
> | ||
<OrganizationsSearchSelect | ||
defaultValue={organization} | ||
disabled | ||
/> | ||
</FormField> | ||
|
||
<FormField | ||
className="uk-margin" | ||
label={t.role.label} | ||
{...validation.extract('role')} | ||
> | ||
<UserOrganizationRoleSelect {...bind.path('role')} required /> | ||
</FormField> | ||
|
||
<hr /> | ||
</> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { | ||
SdkTableRowWithIdT, | ||
SdkUpdateUserInputT, | ||
} from '@llm/sdk'; | ||
|
||
export type UpdateUserFormValue = | ||
SdkTableRowWithIdT & | ||
SdkUpdateUserInputT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
apps/backend/src/migrations/0026-add-users-groups-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { type Kysely, sql } from 'kysely'; | ||
|
||
import { addArchivedAtColumns, addIdColumn, addTimestampColumns } from './utils'; | ||
|
||
export async function up(db: Kysely<any>): Promise<void> { | ||
await db.schema | ||
.createTable('users_groups') | ||
.$call(addIdColumn) | ||
.$call(addTimestampColumns) | ||
.$call(addArchivedAtColumns) | ||
.addColumn('organization_id', 'integer', col => col.notNull().references('organizations.id').onDelete('restrict')) | ||
.addColumn('creator_user_id', 'integer', col => col.notNull().references('users.id').onDelete('restrict')) | ||
.addColumn('name', 'text', col => col.notNull()) | ||
.execute(); | ||
|
||
await db.schema | ||
.createTable('users_groups_users') | ||
.addColumn('user_id', 'integer', col => col.notNull().references('users.id').onDelete('cascade')) | ||
.addColumn('group_id', 'integer', col => col.notNull().references('users_groups.id').onDelete('cascade')) | ||
.addUniqueConstraint('user_id_group_id_unique', ['user_id', 'group_id']) | ||
.execute(); | ||
|
||
await db.schema | ||
.createIndex('users_groups_organization_id_index') | ||
.on('users_groups') | ||
.column('organization_id') | ||
.execute(); | ||
|
||
await sql` | ||
CREATE OR REPLACE FUNCTION users_groups_users_check_organization() RETURNS TRIGGER AS $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM organizations_users ou | ||
JOIN users_groups ug ON ug.organization_id = ou.organization_id | ||
WHERE ou.user_id = NEW.user_id | ||
AND ug.id = NEW.group_id | ||
) THEN | ||
RAISE EXCEPTION 'User must belong to the same organization as the group'; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
CREATE TRIGGER users_groups_users_organization_check | ||
BEFORE INSERT OR UPDATE ON users_groups_users | ||
FOR EACH ROW | ||
EXECUTE FUNCTION users_groups_users_check_organization(); | ||
`.execute(db); | ||
} | ||
|
||
export async function down(db: Kysely<any>): Promise<void> { | ||
await sql` | ||
DROP TRIGGER IF EXISTS users_groups_users_organization_check ON users_groups_users; | ||
DROP FUNCTION IF EXISTS users_groups_users_check_organization(); | ||
`.execute(db); | ||
|
||
await db.schema.dropTable('users_groups_users').execute(); | ||
await db.schema.dropTable('users_groups').execute(); | ||
} |
Oops, something went wrong.