-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: review server actions (#4868)
* chore: review server actions and make sure to delimit public facing functions from internal ones * delete unused server actions * remove privilege checks duplcation * fix issue with error message translation for reset password component * fix merge conflicts
- Loading branch information
Showing
28 changed files
with
572 additions
and
535 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
9 changes: 1 addition & 8 deletions
9
...rms)/[locale]/(app administration)/admin/(with nav)/accounts/[id]/manage-forms/actions.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
25 changes: 13 additions & 12 deletions
25
...locale]/(app administration)/admin/(with nav)/accounts/[id]/manage-permissions/actions.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,25 +1,26 @@ | ||
"use server"; | ||
|
||
import { updatePrivilegesForUser } from "@lib/privileges"; | ||
import { checkPrivilegesAsBoolean } from "@lib/privileges"; | ||
import { revalidatePath } from "next/cache"; | ||
import { authCheckAndThrow } from "@lib/actions"; | ||
|
||
// Public facing functions - they can be used by anyone who finds the associated server action identifer | ||
|
||
export const updatePrivileges = async ( | ||
userID: string, | ||
privilegeID: string, | ||
action: "add" | "remove" | ||
) => { | ||
const { ability } = await authCheckAndThrow(); | ||
if (checkPrivilegesAsBoolean(ability, [{ action: "update", subject: "User" }])) { | ||
try { | ||
const result = await updatePrivilegesForUser(ability, userID, [{ id: privilegeID, action }]); | ||
revalidatePath( | ||
"(gcforms)/[locale]/(app administration)/admin/(with nav)/accounts/[id]/manage-permissions", | ||
"page" | ||
); | ||
return { data: result }; | ||
} catch (e) { | ||
return { error: "Failed to update permissions." }; | ||
} | ||
|
||
try { | ||
const result = await updatePrivilegesForUser(ability, userID, [{ id: privilegeID, action }]); | ||
revalidatePath( | ||
"(gcforms)/[locale]/(app administration)/admin/(with nav)/accounts/[id]/manage-permissions", | ||
"page" | ||
); | ||
return { data: result }; | ||
} catch (e) { | ||
return { error: "Failed to update permissions." }; | ||
} | ||
}; |
17 changes: 7 additions & 10 deletions
17
app/(gcforms)/[locale]/(app administration)/admin/(with nav)/accounts/actions.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
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
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
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
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.