-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lebihae/1025' into 'main'
fix(posts): make delete button actually do something (closes #1025) Closes #1025 See merge request churros/churros!283
- Loading branch information
Showing
13 changed files
with
160 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@churros/app': major | ||
--- | ||
|
||
Remove /posts/:group/create - the URL was not used anywhere in the UI anymore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@churros/api': major | ||
--- | ||
|
||
change return type and argument type for Mutation.deleteArticle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@churros/app': patch | ||
--- | ||
|
||
make delete button on posts work |
43 changes: 20 additions & 23 deletions
43
packages/api/src/modules/posts/resolvers/mutation.delete-article.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
import { builder, log, prisma, publish } from '#lib'; | ||
import { builder, ensureGlobalId, log, prisma, publish } from '#lib'; | ||
import { LocalID } from '#modules/global'; | ||
import { ArticleType, canEditArticle } from '#modules/posts'; | ||
|
||
builder.mutationField('deleteArticle', (t) => | ||
t.field({ | ||
type: 'Boolean', | ||
args: { id: t.arg.id() }, | ||
t.prismaField({ | ||
type: ArticleType, | ||
errors: {}, | ||
description: 'Supprimer un post', | ||
args: { id: t.arg({ type: LocalID }) }, | ||
async authScopes(_, { id }, { user }) { | ||
if (!user) return false; | ||
if (user.canEditGroups) return true; | ||
|
||
const article = await prisma.article.findUniqueOrThrow({ where: { id } }); | ||
|
||
// Who can delete this article? | ||
return ( | ||
// Admins | ||
user.admin || | ||
// The author | ||
user.id === article.authorId || | ||
// Other authors of the group | ||
user.groups.some( | ||
({ groupId, canEditArticles }) => canEditArticles && groupId === article.groupId, | ||
) | ||
); | ||
const post = await prisma.article.findUniqueOrThrow({ | ||
where: { id: ensureGlobalId(id, 'Article') }, | ||
include: canEditArticle.prismaIncludes, | ||
}); | ||
return canEditArticle(post, { authorId: null, group: null }, user); | ||
}, | ||
async resolve(_, { id }, { user }) { | ||
await prisma.article.delete({ where: { id } }); | ||
async resolve(query, _, { id }, { user }) { | ||
id = ensureGlobalId(id, 'Article'); | ||
|
||
await log('article', 'delete', { message: `Article ${id} deleted` }, id, user); | ||
|
||
const result = await prisma.article.delete({ ...query, where: { id } }); | ||
|
||
publish(id, 'deleted', id); | ||
return true; | ||
|
||
return result; | ||
}, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.