Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: all users can edit "Templates" team and moveFlows to teams they're allowed to edit #2239

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ const EditorToolbar: React.FC<{
<Edit />
</ListItemIcon>
<ListItemText>
{user.isPlatformAdmin ? `All teams` : user.teams.map((team) => team.team.name).join(", ")}
{user.isPlatformAdmin ? `All teams` : user.teams.map((team) => team.team.name).concat(["Templates"]).join(", ")}
</ListItemText>
</MenuItem>
)}
Expand Down
9 changes: 8 additions & 1 deletion editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { FlowLayout } from "../../components/Flow";
import { connectToDB, getConnection } from "./../sharedb";
import type { Store } from ".";
import type { SharedStore } from "./shared";
import { UserStore } from "./user";

let doc: any;

Expand Down Expand Up @@ -82,7 +83,7 @@ export interface EditorStore extends Store.Store {
}

export const editorStore: StateCreator<
SharedStore & EditorStore,
SharedStore & EditorStore & UserStore,
[],
[],
EditorStore
Expand Down Expand Up @@ -333,6 +334,12 @@ export const editorStore: StateCreator<
},

moveFlow(flowId: string, teamSlug: string) {
const valid = get().canUserEditTeam(teamSlug);
if (!valid) {
alert(`You do not have permission to move this flow into ${teamSlug}, try again`);
return Promise.resolve();
}

const token = getCookie("jwt");

return axios
Expand Down
8 changes: 3 additions & 5 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ export const userStore: StateCreator<UserStore, [], [], UserStore> = (

canUserEditTeam: (teamSlug) => {
return (
get().teams.filter(
(team) =>
(team.role === "teamEditor" && team.team.slug === teamSlug) ||
get().isPlatformAdmin,
).length > 0
get().isPlatformAdmin ||
teamSlug === "templates" ||
get().teams.filter((team) => team.role === "teamEditor" && team.team.slug === teamSlug).length > 0
);
},
});
Loading