forked from pinterest/querybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user group db schema support (pinterest#1144)
* feat: add user group db schema support * comments * disable user group indexing * addto sidebar * fix linter * more comments * fix linter * typo
- Loading branch information
1 parent
1ff016d
commit 25b127d
Showing
15 changed files
with
251 additions
and
22 deletions.
There are no files selected for viewing
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,33 @@ | ||
--- | ||
id: users_and_groups | ||
title: Users and Groups | ||
sidebar_label: Users and Groups | ||
--- | ||
|
||
Querybook supports adding/loading users and user groups. | ||
|
||
## DB Schema | ||
We use the `User` model to represent a user or a group. | ||
|
||
A user or a group can have below properties | ||
- username: It is the unique identifier of a user or a group. | ||
- fullname: Full name or display name of a user or a group. | ||
- password: Password of a user. Only applies to users when using default user/password auth. | ||
- email: Email of a user or a group. | ||
- profile_img: Profile image url of a user or a group. | ||
- deleted: To indicate if this user has been deleted/deactivated or not. | ||
- is_group: To indicate it is a user group if it's true. | ||
- properties: Any addiontal properties are stored in this column. It is a freeform JSON object, you can basically add any properties inside it. By default all the properties inside `properties` are private, which are invisiable to end users. | ||
- public_info: Only properties stored inside `properties.public_info` are visible to end users. | ||
- description: [optional] Description of a user or a group. | ||
|
||
|
||
For the detailed DB schema and table relationships, please check the model file [here](https://github.com/pinterest/querybook/blob/master/querybook/server/models/user.py) | ||
|
||
|
||
## Create/Load Users and Group | ||
For users | ||
- default user/password authentication: people can sign up as a new user on UI. | ||
- oauth/ldap authentication: they both support auto-creation of users. | ||
|
||
For user groups, they can only be sync'ed now and can not be created on UI. You can have a scheduled task for your organization to sync them from either ldap, metastore or any other system which contains user groups. |
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
39 changes: 39 additions & 0 deletions
39
querybook/migrations/versions/1b8aba201c94_add_user_group_support.py
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,39 @@ | ||
"""add user group support | ||
Revision ID: 1b8aba201c94 | ||
Revises: 27ed76f75106 | ||
Create Date: 2023-02-03 00:31:09.209132 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1b8aba201c94" | ||
down_revision = "27ed76f75106" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"user_group_member", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("gid", sa.Integer(), nullable=False), | ||
sa.Column("uid", sa.Integer(), nullable=False), | ||
sa.Column("created_at", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint(["gid"], ["user.id"], ondelete="CASCADE"), | ||
sa.ForeignKeyConstraint(["uid"], ["user.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.add_column("user", sa.Column("is_group", sa.Boolean(), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("user", "is_group") | ||
op.drop_table("user_group_member") | ||
# ### end Alembic commands ### |
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.UserGroupCard { | ||
max-width: 400px; | ||
|
||
.members-container { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
querybook/webapp/components/UserGroupCard/UserGroupCard.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,73 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import { UserBadge } from 'components/UserBadge/UserBadge'; | ||
import { MAX_USER_GROUP_MEMBERS_TO_SHOW } from 'const/uiConfig'; | ||
import { IUserInfo } from 'const/user'; | ||
import { useResource } from 'hooks/useResource'; | ||
import { UserResource } from 'resource/user'; | ||
import { AccentText } from 'ui/StyledText/StyledText'; | ||
|
||
import './UserGroupCard.scss'; | ||
|
||
interface IProps { | ||
userGroup: IUserInfo; | ||
} | ||
|
||
export const UserGroupCard = ({ userGroup }: IProps) => { | ||
const { data: members } = useResource( | ||
useCallback( | ||
() => UserResource.getUserGroupMembers(userGroup.id), | ||
[userGroup.id] | ||
) | ||
); | ||
|
||
const membersDOM = members && ( | ||
<> | ||
{members.slice(0, MAX_USER_GROUP_MEMBERS_TO_SHOW).map((m) => ( | ||
<div key={m.id} className="flex-row ml8"> | ||
<UserBadge uid={m.id} mini /> | ||
</div> | ||
))} | ||
{members.length > MAX_USER_GROUP_MEMBERS_TO_SHOW && ( | ||
<div className="ml8"> and more</div> | ||
)} | ||
</> | ||
); | ||
|
||
return ( | ||
<div className="UserGroupCard"> | ||
<div> | ||
<AccentText color="dark" weight="bold" size="xsmall"> | ||
{userGroup.fullname ?? userGroup.username} | ||
</AccentText> | ||
<AccentText color="light" size="xsmall"> | ||
{userGroup.username} | ||
</AccentText> | ||
</div> | ||
{userGroup.email && ( | ||
<div className="mt8"> | ||
<AccentText color="dark" weight="bold" size="xsmall"> | ||
</AccentText> | ||
<AccentText color="light" size="xsmall"> | ||
{userGroup.email} | ||
</AccentText> | ||
</div> | ||
)} | ||
<div className="mt8"> | ||
<AccentText color="dark" weight="bold" size="xsmall"> | ||
Description | ||
</AccentText> | ||
<AccentText color="light" size="xsmall"> | ||
{userGroup.properties.description} | ||
</AccentText> | ||
</div> | ||
<div className="mt8"> | ||
<AccentText color="dark" weight="bold" size="xsmall"> | ||
Group members | ||
</AccentText> | ||
<div className="members-container">{membersDOM}</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
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