-
Notifications
You must be signed in to change notification settings - Fork 225
feat: Create ReadOnly user components #7610
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
Merged
jam411
merged 7 commits into
feat/120698-read-only-user
from
feat/120698-120954-rom-user-client
Apr 29, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52887f8
create read only services
cc08ae9
create read only components
bbfa270
create translation files
f545674
create read only badge
cc45201
Merge branch 'feat/120698-read-only-user' into feat/120698-120954-rom…
4ee54c0
apply feedback
9d5fc38
refactor use ternary operator
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
apps/app/src/components/Admin/Users/GiveReadOnlyButton.tsx
This file contains hidden or 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,40 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import type { IUserHasId } from '@growi/core'; | ||
import { useTranslation } from 'next-i18next'; | ||
|
||
import AdminUsersContainer from '~/client/services/AdminUsersContainer'; | ||
import { toastSuccess, toastError } from '~/client/util/toastr'; | ||
|
||
import { withUnstatedContainers } from '../../UnstatedUtils'; | ||
|
||
const GiveReadOnlyButton: React.FC<{ | ||
adminUsersContainer: AdminUsersContainer, | ||
user: IUserHasId, | ||
}> = ({ adminUsersContainer, user }): JSX.Element => { | ||
const { t } = useTranslation('admin'); | ||
|
||
const onClickGiveReadOnlyBtnHandler = useCallback(async() => { | ||
try { | ||
const username = await adminUsersContainer.giveUserReadOnly(user._id); | ||
toastSuccess(t('toaster.give_user_read_only', { username })); | ||
} | ||
catch (err) { | ||
toastError(err); | ||
} | ||
}, [adminUsersContainer, t, user._id]); | ||
|
||
return ( | ||
<button className="dropdown-item" type="button" onClick={onClickGiveReadOnlyBtnHandler}> | ||
<i className="icon-fw icon-user-following"></i> {t('user_management.user_table.give_read_only_access')} | ||
</button> | ||
); | ||
}; | ||
|
||
/** | ||
* Wrapper component for using unstated | ||
*/ | ||
// eslint-disable-next-line max-len | ||
const GiveReadOnlyButtonWrapper: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<any>> = withUnstatedContainers(GiveReadOnlyButton, [AdminUsersContainer]); | ||
|
||
export default GiveReadOnlyButtonWrapper; |
40 changes: 40 additions & 0 deletions
40
apps/app/src/components/Admin/Users/RemoveReadOnlyMenuItem.tsx
This file contains hidden or 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,40 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import type { IUserHasId } from '@growi/core'; | ||
import { useTranslation } from 'next-i18next'; | ||
|
||
import AdminUsersContainer from '~/client/services/AdminUsersContainer'; | ||
import { toastSuccess, toastError } from '~/client/util/toastr'; | ||
|
||
import { withUnstatedContainers } from '../../UnstatedUtils'; | ||
|
||
const RemoveReadOnlyMenuItem: React.FC<{ | ||
adminUsersContainer: AdminUsersContainer, | ||
user: IUserHasId, | ||
}> = ({ adminUsersContainer, user }): JSX.Element => { | ||
const { t } = useTranslation('admin'); | ||
|
||
const clickRemoveReadOnlyBtnHandler = useCallback(async() => { | ||
try { | ||
const username = await adminUsersContainer.removeUserReadOnly(user._id); | ||
toastSuccess(t('toaster.remove_user_read_only', { username })); | ||
} | ||
catch (err) { | ||
toastError(err); | ||
} | ||
}, [adminUsersContainer, t, user._id]); | ||
|
||
return ( | ||
<button className="dropdown-item" type="button" onClick={clickRemoveReadOnlyBtnHandler}> | ||
<i className="icon-fw icon-user-unfollow"></i> {t('user_management.user_table.remove_read_only_access')} | ||
</button> | ||
); | ||
}; | ||
|
||
/** | ||
* Wrapper component for using unstated | ||
*/ | ||
// eslint-disable-next-line max-len | ||
const RemoveReadOnlyMenuItemWrapper: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<any>> = withUnstatedContainers(RemoveReadOnlyMenuItem, [AdminUsersContainer]); | ||
|
||
export default RemoveReadOnlyMenuItemWrapper; |
This file contains hidden or 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 |
---|---|---|
|
@@ -11,7 +11,9 @@ import AdminUsersContainer from '~/client/services/AdminUsersContainer'; | |
import { withUnstatedContainers } from '../../UnstatedUtils'; | ||
|
||
import GiveAdminButton from './GiveAdminButton'; | ||
import GiveReadOnlyButton from './GiveReadOnlyButton'; | ||
import RemoveAdminMenuItem from './RemoveAdminMenuItem'; | ||
import RemoveReadOnlyMenuItem from './RemoveReadOnlyMenuItem'; | ||
import SendInvitationEmailButton from './SendInvitationEmailButton'; | ||
import StatusActivateButton from './StatusActivateButton'; | ||
import StatusSuspendedMenuItem from './StatusSuspendMenuItem'; | ||
|
@@ -81,8 +83,10 @@ const UserMenu = (props: UserMenuProps) => { | |
<li className="dropdown-divider pl-0"></li> | ||
<li className="dropdown-header">{t('user_management.user_table.administrator_menu')}</li> | ||
<li> | ||
{user.admin === true && <RemoveAdminMenuItem user={user} />} | ||
{user.admin === false && <GiveAdminButton user={user} />} | ||
{user.admin ? <RemoveAdminMenuItem user={user} /> : <GiveAdminButton user={user} />} | ||
</li> | ||
<li> | ||
{user.readOnly ? <RemoveReadOnlyMenuItem user={user} /> : <GiveReadOnlyButton user={user} />} | ||
</li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 前バージョンからアップグレードしたシステムだと 一方 admin は必ず T/F のどちらかが入っているが、可読性を考慮して書式を揃えてもよい。 |
||
</> | ||
); | ||
|
This file contains hidden or 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 hidden or 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.
別に管理者自身も ROM にできていいと思うよ
Uh oh!
There was an error while loading. Please reload this page.
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.
管理者も ROM にできるように修正しました。
細かいですが、
Read Only Member でなく Read Only User (日本語では”閲覧ユーザー")として作ってしまったのですが、
Read Only Member (日本語では "閲覧メンバー" )の方がよいでしょうか。