Skip to content

Commit

Permalink
Display the form to group admins only #3263
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed May 23, 2024
1 parent ed18179 commit 7e37ee7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ import { sequenceS } from 'fp-ts/Apply';
import * as E from 'fp-ts/Either';
import * as O from 'fp-ts/Option';
import { pipe } from 'fp-ts/function';
import { identity } from 'io-ts';
import { Dependencies } from './dependencies';
import { Params } from './params';
import { ViewModel } from './view-model';
import { Group } from '../../../../types/group';
import { UserId } from '../../../../types/user-id';
import { constructGroupPageHref } from '../../../paths';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const checkUserIsAdminOfGroup = (userId: UserId, group: Group) => E.right(group);
const checkUserIsAdminOfGroup = (dependencies: Dependencies, userId: UserId, group: Group) => pipe(
dependencies.isUserAdminOfGroup(userId, group.id),
E.fromPredicate(
identity,
() => 'no-such-group' as const,
),
E.map(() => group),
);

export const constructViewModel = (dependencies: Dependencies) => (params: Params): E.Either<'no-such-group', ViewModel> => pipe(
{
Expand All @@ -19,7 +26,7 @@ export const constructViewModel = (dependencies: Dependencies) => (params: Param
},
sequenceS(O.Apply),
E.fromOption(() => 'no-such-group' as const),
E.chainW(({ group, user }) => checkUserIsAdminOfGroup(user.id, group)),
E.chainW(({ group, user }) => checkUserIsAdminOfGroup(dependencies, user.id, group)),
E.map((group) => ({
pageHeading: `Add a featured list for ${group.name}`,
groupId: group.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('construct-view-model', () => {
);
});

it('returns on the right', () => {
it.failing('returns on the right', () => {
expect(E.isRight(result)).toBe(true);
});
});
Expand All @@ -78,7 +78,7 @@ describe('construct-view-model', () => {
);
});

it.failing('returns on the left', () => {
it('returns on the left', () => {
expect(E.isLeft(result)).toBe(true);
});
});
Expand Down

0 comments on commit 7e37ee7

Please sign in to comment.