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 5 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>;
}
15 changes: 12 additions & 3 deletions FrontEnd/src/pages/AdminPage/Menu/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const MENU = [
title: 'Зміна часу автомодерації',
link: '/customadmin/automoderation/'
},
];

const SUPERUSER_MENU = [
{
id: 'am5',
title: 'Пошта адміністратора',
Expand All @@ -33,7 +36,8 @@ const MENU = [
];

function Menu() {
const { isAuth, logout } = useAuth();
const { isAuth, logout, isSuperUser } = useAuth();

const handleLogout = async () => {
if (isAuth) {
axios.post(`${process.env.REACT_APP_BASE_API_URL}/api/auth/token/logout`)
Expand All @@ -45,8 +49,13 @@ function Menu() {

return (
<div className={css['menu-section']}>
{MENU.map((element) => (
<Link className={css['menu-section-element']} key={element.id} to={element.link}>{element.title}</Link>
{[
...MENU,
...(isSuperUser ? SUPERUSER_MENU : [])
].map((element) => (
<Link className={css['menu-section-element']} key={element.id} to={element.link}>
{element.title}
</Link>
))}
<div className={css['menu-section-divider']}></div>
<button className={css['menu-section-logout']} onClick={handleLogout}>Вихід</button>
Expand Down
6 changes: 4 additions & 2 deletions FrontEnd/src/routes/AdminRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Contacts from '../pages/AdminPage/DetailView/Contacts';


function AdminRouter() {
const { isLoading, isAuth, isStaff } = useAuth();
const { isLoading, isAuth, isStaff, isSuperUser } = useAuth();
const renderMenu = isStaff && isAuth ? <Menu /> : null;
const authRoutes = isStaff && isAuth ? (
<>
Expand All @@ -27,7 +27,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 />} />
</>
) : (
Expand Down
Loading