Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
⏪ Partially revert logic for hiding stab (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieladugyan authored Aug 21, 2023
1 parent aa07d57 commit 6051d1b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 63 deletions.
12 changes: 0 additions & 12 deletions backend/services/core/src/datasources/Mandate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export default class MandateAPI extends dbUtils.KnexDataSource {
return this.withAccess('core:mandate:read', ctx, async () => {
const res = (await this.knex<sql.Mandate>('mandates').select('*').where({ id }))[0];

if (await this.isStabHidden() && STAB_IDS.includes(res.position_id)) {
return undefined;
}

if (!res) { return undefined; }
return convertMandate(res);
});
Expand Down Expand Up @@ -110,14 +106,6 @@ export default class MandateAPI extends dbUtils.KnexDataSource {
query = query.andWhereRaw('CURRENT_DATE BETWEEN start_date AND end_date');
}
const res = await query;
if (await this.isStabHidden()) {
// if user has an active stab mandate, hide all other mandates
if (res.some((m) => m.end_date > new Date() && STAB_IDS.includes(m.position_id))) {
return [];
}
// otherwise just filter out their old stab mandates
return res.filter((m) => !STAB_IDS.includes(m.position_id)).map(convertMandate);
}
return res.map(convertMandate);
});
}
Expand Down
4 changes: 0 additions & 4 deletions backend/services/core/src/datasources/Position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export default class PositionAPI extends dbUtils.KnexDataSource {
return undefined;
}

if (await this.isStabHidden() && STAB_IDS.includes(position.id)) {
return undefined;
}

if (!position.active) {
await this.withAccess('core:position:inactive:read', ctx, async () => { });
}
Expand Down
114 changes: 67 additions & 47 deletions frontend/pages/members/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Box,
Button, Paper, Stack, Tooltip,
Box, Button, Paper, Stack, Tooltip,
} from '@mui/material';
import { i18n, useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
Expand All @@ -20,13 +19,18 @@ import { useMemberPageQuery, usePingMemberMutation } from '~/generated/graphql';
import { useApiAccess } from '~/providers/ApiAccessProvider';
import { useSetPageName } from '~/providers/PageNameProvider';
import UserContext from '~/providers/UserProvider';
import routes from '~/routes'; import commonPageStyles from '~/styles/commonPageStyles';
import routes from '~/routes';
import commonPageStyles from '~/styles/commonPageStyles';

export default function MemberPage() {
const router = useRouter();
const id = router.query.id as string;
const { user, loading: userLoading } = useContext(UserContext);
const { loading, data: userData, refetch } = useMemberPageQuery({
const {
loading,
data: userData,
refetch,
} = useMemberPageQuery({
variables: idOrStudentId(id),
});
const member = userData?.member;
Expand All @@ -43,9 +47,7 @@ export default function MemberPage() {
const isMe = user?.id === member?.id;
useSetPageName(
member ? getFullName(member, false) : MEMBER_TEXT,
isMe
? selectTranslation(i18n, 'Profil', 'Profile')
: MEMBER_TEXT,
isMe ? selectTranslation(i18n, 'Profil', 'Profile') : MEMBER_TEXT,
);

if (loading || userLoading) {
Expand All @@ -61,52 +63,70 @@ export default function MemberPage() {
if (!member) {
return <>{t('member:memberError')}</>;
}
if (
member.activeMandates.some(
(m) => m.position.id === 'dsek.noll.stab.mdlm',
)
&& member.id !== user?.id
&& !hasAccess('nolla:admin')
) {
return <>{t('member:memberError')}</>;
}
return (
<NoTitleLayout>
<Paper className={classes.innerContainer}>
<Member
member={member}
/>
<Stack direction="row" gap={2} marginTop={4} justifyContent="space-between" flexWrap="wrap">
<Member member={member} />
<Stack
direction="row"
gap={2}
marginTop={4}
justifyContent="space-between"
flexWrap="wrap"
>
{(member.id === user?.id || hasAccess('core:member:update')) && (
<Stack direction="row" gap={2} flexWrap="wrap">
<Link href={routes.editMember(member.id)}>
<Button variant="contained" startIcon={<EditIcon />}>
{t('member:editMember')}
</Button>
</Link>
<Link href={routes.changeProfilePicture(member.id)}>
<Button startIcon={<PortraitIcon />}>
{t('member:changeProfilePicture')}
</Button>
</Link>
</Stack>
)}
{hasAccess('core:member:ping') && (member.id !== user?.id ? (
<Tooltip title={!member.canPing ? t('member:pingWaitForResponse') : t('member:pingTooltip')}>
<Box>
<Button
variant="outlined"
disabled={!member.canPing}
onClick={async () => {
await ping();
refetch();
}}
startIcon={<AdsClickIcon />}
>
{t('member:ping')}
<Stack direction="row" gap={2} flexWrap="wrap">
<Link href={routes.editMember(member.id)}>
<Button variant="contained" startIcon={<EditIcon />}>
{t('member:editMember')}
</Button>
</Box>
</Tooltip>
) : (
<Link href={routes.pings}>
<Button
startIcon={<AdsClickIcon />}
</Link>
<Link href={routes.changeProfilePicture(member.id)}>
<Button startIcon={<PortraitIcon />}>
{t('member:changeProfilePicture')}
</Button>
</Link>
</Stack>
)}
{hasAccess('core:member:ping')
&& (member.id !== user?.id ? (
<Tooltip
title={
!member.canPing
? t('member:pingWaitForResponse')
: t('member:pingTooltip')
}
>
{t('member:myPings')}
</Button>
</Link>
))}
<Box>
<Button
variant="outlined"
disabled={!member.canPing}
onClick={async () => {
await ping();
refetch();
}}
startIcon={<AdsClickIcon />}
>
{t('member:ping')}
</Button>
</Box>
</Tooltip>
) : (
<Link href={routes.pings}>
<Button startIcon={<AdsClickIcon />}>
{t('member:myPings')}
</Button>
</Link>
))}
</Stack>
</Paper>
</NoTitleLayout>
Expand Down

0 comments on commit 6051d1b

Please sign in to comment.