Skip to content

Commit

Permalink
feat: pilot run for new policy (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung authored Apr 1, 2023
1 parent 1fd1d02 commit ebd0048
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
26 changes: 12 additions & 14 deletions app/components/SidebarNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,18 @@ function SidebarNavigation({
<List
title={`Hi, ${profile.name}`}
action={
isMaintainer(profile.name) ? (
<NavLink
className={({ isActive }) =>
clsx(
'flex items-center justify-center gap-2',
isActive ? 'text-white' : 'hover:text-gray-300',
)
}
to="/submit"
prefetch="intent"
>
<SvgIcon className="w-3 h-3" href={plusIcon} />
</NavLink>
) : null
<NavLink
className={({ isActive }) =>
clsx(
'flex items-center justify-center gap-2',
isActive ? 'text-white' : 'hover:text-gray-300',
)
}
to="/submit"
prefetch="intent"
>
<SvgIcon className="w-3 h-3" href={plusIcon} />
</NavLink>
}
>
{isMaintainer(profile?.name) ? (
Expand Down
10 changes: 9 additions & 1 deletion app/routes/_layout.resources.$resourceId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useMemo } from 'react';
import clsx from 'clsx';
import ResourcesDetails from '~/components/ResourcesDetails';
import SuggestedResources from '~/components/SuggestedResources';
import { formatMeta, notFound } from '~/helpers';
import { formatMeta, isMaintainer, notFound } from '~/helpers';
import { getSuggestions, patchResource } from '~/resources';
import BookmarkDetails from '~/components/BookmarkDetails';
import { useSessionData } from '~/hooks';
Expand Down Expand Up @@ -63,6 +63,10 @@ export async function action({ params, context, request }: ActionArgs) {
break;
}
case 'update': {
if (!isMaintainer(profile.name)) {
return new Response('Unauthorized', { status: 401 });
}

const description = formData.get('description')?.toString() ?? null;
const lists = formData.getAll('lists').map((value) => value.toString());

Expand All @@ -78,6 +82,10 @@ export async function action({ params, context, request }: ActionArgs) {
});
}
case 'delete': {
if (!isMaintainer(profile.name)) {
return new Response('Unauthorized', { status: 401 });
}

await resourceStore.deleteBookmark(resourceId);

return redirect('/', {
Expand Down
13 changes: 3 additions & 10 deletions app/routes/_layout.submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ export async function action({ request, context }: ActionArgs) {
),
},
});
} else if (!isMaintainer(profile.name)) {
return redirect('/submit', {
headers: {
'Set-Cookie': await session.flash(
'Sorry. This feature is not enabled on your account yet.',
'warning',
),
},
});
}

const formData = await request.formData();
Expand Down Expand Up @@ -105,7 +96,9 @@ export async function action({ request, context }: ActionArgs) {
}

return redirect(
`/resources/${id}?${new URLSearchParams({ open: 'bookmark' })}`,
isMaintainer(profile.name)
? `/resources/${id}?${new URLSearchParams({ open: 'bookmark' })}`
: `/resources/${id}`,
{ headers },
);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test.describe.parallel('Permission', () => {
).toBeDefined();
});

test('fails as a user', async ({ page, queries, mockAgent }) => {
test.skip('fails as a user', async ({ page, queries, mockAgent }) => {
const url = 'http://example.com/user';

await login(page, mockAgent, 'github-username');
Expand Down

0 comments on commit ebd0048

Please sign in to comment.