diff --git a/backend/core/factories.py b/backend/core/factories.py index 246ea788f..7a753d647 100644 --- a/backend/core/factories.py +++ b/backend/core/factories.py @@ -11,7 +11,7 @@ class Meta: last_name = "Doe" username = "janed" email = "jane.doe@gmail.com" - password = factory.PostGenerationMethodCall("set_password", "janedoe") + password = factory.PostGenerationMethodCall("set_password", "janed") class AdminFactory(UserFactory): diff --git a/backend/core/serializers.py b/backend/core/serializers.py index cab63acfe..cae636a49 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -6,7 +6,7 @@ class UserSerializer(serializers.ModelSerializer): class Meta: ref_name = "core.user" model = User - fields = ("id", "first_name", "last_name", "email", "username") + fields = ("id", "first_name", "last_name", "email", "username", "is_staff") class UserIdAndNameSerializer(serializers.ModelSerializer): diff --git a/frontend/src/components/Root/components/Header/components/AccountMenu/AccountMenu.tsx b/frontend/src/components/Root/components/Header/components/AccountMenu/AccountMenu.tsx index 8649ddd64..3e8afbd78 100644 --- a/frontend/src/components/Root/components/Header/components/AccountMenu/AccountMenu.tsx +++ b/frontend/src/components/Root/components/Header/components/AccountMenu/AccountMenu.tsx @@ -6,13 +6,13 @@ import { UserState } from 'redux/user/reducer'; import { routeDefinitions } from 'routes'; import { Container, - UserActionItem, - UserActionItemExternalLink, - UserActionsBlock, - UserEmail, - UserInfosBlock, - UserInfosBlockContainer, - UserName + UserActionItem, + UserActionItemExternalLink, + UserActionsBlock, + UserEmail, + UserInfosBlock, + UserInfosBlockContainer, + UserName, } from './AccountMenu.style'; interface OwnProps { @@ -71,17 +71,23 @@ export const AccountMenu: React.FunctionComponent<Props> = ({ </UserInfosBlock> </UserInfosBlockContainer> <UserActionsBlock> - <UserActionItem - margin={'0'} - > - <UserActionItemExternalLink href="https://getfal.co" target="_blank" rel="noopener noreferrer"> + <UserActionItem margin={'0'}> + <UserActionItemExternalLink + href="https://getfal.co" + target="_blank" + rel="noopener noreferrer" + > <FormattedMessage id="Header.see_the_docs" /> </UserActionItemExternalLink> </UserActionItem> - <UserActionItem - margin={'0'} - onClick={() => logoutUser(routeDefinitions.landing.path)} - > + {user.isStaff && ( + <UserActionItem margin={'0'}> + <UserActionItemExternalLink href="/admin/" target="_blank" rel="noopener noreferrer"> + <FormattedMessage id="Header.go_to_admin" /> + </UserActionItemExternalLink> + </UserActionItem> + )} + <UserActionItem margin={'0'} onClick={() => logoutUser(routeDefinitions.landing.path)}> <FormattedMessage id="Header.logout_link" /> </UserActionItem> </UserActionsBlock> diff --git a/frontend/src/redux/user/modelizer.ts b/frontend/src/redux/user/modelizer.ts index 65a28b968..8eea5947c 100644 --- a/frontend/src/redux/user/modelizer.ts +++ b/frontend/src/redux/user/modelizer.ts @@ -6,4 +6,5 @@ export const modelizeUser = (user: ApiUser): User => ({ lastName: user.last_name, emailAddress: user.email, username: user.username, + isStaff: user.is_staff, }); diff --git a/frontend/src/redux/user/reducer.ts b/frontend/src/redux/user/reducer.ts index 8e9e7636c..bbb9b7e1e 100644 --- a/frontend/src/redux/user/reducer.ts +++ b/frontend/src/redux/user/reducer.ts @@ -3,13 +3,16 @@ import { ActionType, getType } from 'typesafe-actions'; import { fetchUserError, fetchUserRequest, fetchUserSuccess } from './actions'; -export type UserAction = ActionType<typeof fetchUserError | typeof fetchUserRequest | typeof fetchUserSuccess>; +export type UserAction = ActionType< + typeof fetchUserError | typeof fetchUserRequest | typeof fetchUserSuccess +>; export type UserState = Readonly<{ firstName: string; lastName: string; emailAddress: string; username: string; + isStaff: boolean; } | null>; const initialState: UserState = null; diff --git a/frontend/src/redux/user/types.ts b/frontend/src/redux/user/types.ts index 5fa5e48b8..09283819f 100644 --- a/frontend/src/redux/user/types.ts +++ b/frontend/src/redux/user/types.ts @@ -4,6 +4,7 @@ export interface User { lastName: string; emailAddress: string; username: string; + isStaff: boolean; } export interface ApiUser { @@ -12,4 +13,5 @@ export interface ApiUser { first_name: string; last_name: string; email: string; + is_staff: boolean; } diff --git a/frontend/src/translations/en.json b/frontend/src/translations/en.json index 14131200e..65854f1ab 100644 --- a/frontend/src/translations/en.json +++ b/frontend/src/translations/en.json @@ -1,5 +1,6 @@ { "Header": { + "go_to_admin": "Go to the admin interface", "logo_title_landing": "Home page", "logo_title_app": "Refresh the page", "login_link": "LOG IN", @@ -210,7 +211,7 @@ "join_project": "To join an existing project, please contact the project administrator." }, "Toastr": { - "ProjectSettings":{ + "ProjectSettings": { "success_title": "Success", "error_title": "Failure", "error_message": "An error occured, please try again", diff --git a/frontend/src/translations/fa.json b/frontend/src/translations/fa.json index ffe96d6ea..377640769 100644 --- a/frontend/src/translations/fa.json +++ b/frontend/src/translations/fa.json @@ -1,5 +1,6 @@ { "Header": { + "go_to_admin": "به رابط مدیریت دسترسی پیدا کنید", "logo_title_landing": "صفحه اصلی", "logo_title_app": "بروز کردن صفحه", "login_link": "ورود", @@ -210,7 +211,7 @@ "join_project": "برای پیوستن به یک پروژه موجود، لطفا با مدیر پروژه تماس بگیرید." }, "Toastr": { - "ProjectSettings":{ + "ProjectSettings": { "success_title": "موفق", "error_title": "نا موفق", "error_message": "خطایی رخ داد، لطفا مجددا تلاش کنید", diff --git a/frontend/src/translations/fr.json b/frontend/src/translations/fr.json index d44ce4f76..237c75a58 100644 --- a/frontend/src/translations/fr.json +++ b/frontend/src/translations/fr.json @@ -1,5 +1,6 @@ { "Header": { + "go_to_admin": "Accèder à l'interface d'admin", "logo_title_landing": "Page d'accueil", "logo_title_app": "Rafraîchir la page", "login_link": "SE CONNECTER", @@ -210,7 +211,7 @@ "join_project": "Pour rejoindre un projet existant, veuillez contacter l'administrateur du projet." }, "Toastr": { - "ProjectSettings":{ + "ProjectSettings": { "success_title": "Succès", "error_title": "Échec", "error_message": "Une erreur est survenue, veuillez réessayer",