Skip to content

Commit

Permalink
Add link to admin interface (#135)
Browse files Browse the repository at this point in the history
* Change janed password for consistency

* Returns the is_staff status for the user

* Add link to /admin/ only if user is staff
  • Loading branch information
phacks authored Mar 19, 2020
1 parent e184be5 commit e20e1ff
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/core/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Meta:
last_name = "Doe"
username = "janed"
email = "[email protected]"
password = factory.PostGenerationMethodCall("set_password", "janedoe")
password = factory.PostGenerationMethodCall("set_password", "janed")


class AdminFactory(UserFactory):
Expand Down
2 changes: 1 addition & 1 deletion backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/redux/user/modelizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export const modelizeUser = (user: ApiUser): User => ({
lastName: user.last_name,
emailAddress: user.email,
username: user.username,
isStaff: user.is_staff,
});
5 changes: 4 additions & 1 deletion frontend/src/redux/user/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/redux/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface User {
lastName: string;
emailAddress: string;
username: string;
isStaff: boolean;
}

export interface ApiUser {
Expand All @@ -12,4 +13,5 @@ export interface ApiUser {
first_name: string;
last_name: string;
email: string;
is_staff: boolean;
}
3 changes: 2 additions & 1 deletion frontend/src/translations/en.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/fa.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"Header": {
"go_to_admin": "به رابط مدیریت دسترسی پیدا کنید",
"logo_title_landing": "صفحه اصلی",
"logo_title_app": "بروز کردن صفحه",
"login_link": "ورود",
Expand Down Expand Up @@ -210,7 +211,7 @@
"join_project": "برای پیوستن به یک پروژه موجود، لطفا با مدیر پروژه تماس بگیرید."
},
"Toastr": {
"ProjectSettings":{
"ProjectSettings": {
"success_title": "موفق",
"error_title": "نا موفق",
"error_message": "خطایی رخ داد، لطفا مجددا تلاش کنید",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/translations/fr.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e20e1ff

Please sign in to comment.