-
Notifications
You must be signed in to change notification settings - Fork 247
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
feat: add user group db schema support #1144
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8e89c07
feat: add user group db schema support
jczhong84 707d7a8
comments
jczhong84 52a6284
disable user group indexing
jczhong84 447ba76
addto sidebar
jczhong84 e25345f
fix linter
jczhong84 dabaeb5
more comments
jczhong84 f918a47
fix linter
jczhong84 6f273c9
typo
jczhong84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. | ||
- auth/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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oauth