Skip to content
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

#816 hiding moderator's email setup option in admin panel #819

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BackEnd/authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Meta(UserSerializer.Meta):
"surname",
"profile_id",
"is_staff",
"is_superuser",
)


Expand Down
1 change: 1 addition & 0 deletions BackEnd/authentication/tests/test_user_autologout.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_user_autologout_after_10_days(self):
"surname": "Test",
"profile_id": AnyInt(),
"is_staff": False,
"is_superuser": False,
},
response.json(),
)
4 changes: 4 additions & 0 deletions BackEnd/authentication/tests/test_user_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_user_retreive_data_successful(self):
"surname": "Test",
"profile_id": AnyInt(),
"is_staff": False,
"is_superuser": False,
},
response.json(),
)
Expand All @@ -54,6 +55,7 @@ def test_user_update_all_fields_successful(self):
"surname": "Ivanenko",
"profile_id": AnyInt(),
"is_staff": False,
"is_superuser": False,
},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand All @@ -65,6 +67,7 @@ def test_user_update_all_fields_successful(self):
"surname": "Ivanenko",
"profile_id": AnyInt(),
"is_staff": False,
"is_superuser": False,
},
response.json(),
)
Expand All @@ -86,6 +89,7 @@ def test_user_update_one_field_successful(self):
"surname": "Petrenko",
"profile_id": AnyInt(),
"is_staff": False,
"is_superuser": False,
},
response.json(),
)
Expand Down
1 change: 1 addition & 0 deletions FrontEnd/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FrontEnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"react": "^18.2.0",
"react-cookie": "^6.1.0",
"react-dom": "^18.2.0",
"react-google-recaptcha": "^3.1.0",
"react-hook-form": "^7.45.4",
"react-router-dom": "^6.22.3",
"react-router-hash-link": "^2.4.3",
"react-scripts": "^5.0.1",
"react-timer-hook": "^3.0.7",
"react-toastify": "^9.1.3",
"react-google-recaptcha": "^3.1.0",
"swr": "^2.2.2",
"validator": "^13.11.0",
"web-vitals": "^2.1.4"
Expand Down
4 changes: 3 additions & 1 deletion FrontEnd/src/context/AuthContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function AuthProvider({ children }) {
const [isLoading, setLoading] = useState(true);
const [authToken, setAuthToken] = useState(localStorage.getItem('Token'));
const [isStaff, setIsStaff] = useState(false);
const [isSuperUser, setIsSuperUser] = useState(false);
const { data, error, mutate } = useSWR(
authToken
? [`${process.env.REACT_APP_BASE_API_URL}/api/auth/users/me/`, authToken]
Expand Down Expand Up @@ -70,6 +71,7 @@ export function AuthProvider({ children }) {
if (data) {
setUser(data);
setIsStaff(data.is_staff);
setIsSuperUser(data.is_superuser);
}
if (error) {
setUser(null);
Expand All @@ -93,7 +95,7 @@ export function AuthProvider({ children }) {
});
});

const value = { login, logout, isAuth, authToken, isLoading, isStaff, user, error, mutate };
const value = { login, logout, isAuth, authToken, isLoading, isStaff, isSuperUser, user, error, mutate };

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
11 changes: 9 additions & 2 deletions FrontEnd/src/pages/AdminPage/Menu/Menu.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NavLink } from 'react-router-dom';

import { useAuth } from '../../../hooks';
import css from './Menu.module.css';

const MENU = [
Expand All @@ -23,6 +23,9 @@ const MENU = [
title: 'Зміна часу автомодерації',
link: '/customadmin/automoderation/'
},
];

const SUPERUSER_MENU = [
{
id: 'am5',
title: 'Пошта адміністратора',
Expand All @@ -31,10 +34,14 @@ const MENU = [
];

function Menu() {
const { isSuperUser } = useAuth();

return (
<div className={css['menu-section']}>
{MENU.map((element) => (
{[
...MENU,
...(isSuperUser ? SUPERUSER_MENU : [])
].map((element) => (
<NavLink
className={({ isActive }) => (`${css['menu-section-element']} ${isActive && css['menu-section-element__active']}`)}
key={element.id} to={element.link}>{element.title}
Expand Down
7 changes: 5 additions & 2 deletions FrontEnd/src/routes/AdminRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import '../pages/AdminPage/AdminGlobal.css';
import css from '../pages/AdminPage/AdminPage.module.css';

function AdminRouter() {
const { isLoading, isAuth, isStaff, user } = useAuth();
const { isLoading, isAuth, isStaff, isSuperUser, user } = useAuth();
const { pathname } = useLocation();
const hideMenu = pathname.includes('/admin-profile/');
const renderMenu = isStaff && isAuth && !hideMenu ? <Menu /> : null;

const authRoutes = isStaff && isAuth ? (
<>
<Route path="/" element={<MainPage />} />
Expand All @@ -32,7 +33,9 @@ function AdminRouter() {
<Route path="/profiles" element={<ProfilesTable />} />
<Route path="/profile/:id" element={<ProfileDetail />} />
<Route path="/automoderation" element={<AutoApproveDelay />} />
<Route path="/email" element={<ModerationEmail />} />
{isSuperUser && (
<Route path="/email" element={<ModerationEmail />} />
)}
<Route path="/contacts" element={<Contacts />} />
<Route path="/admin-profile/*" element={<AdminProfilePage />} />
</>
Expand Down
Loading