Skip to content

Commit

Permalink
fix: use createdBy along with redactedBy to allow user to edit a report
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Sep 23, 2024
1 parent 334dce3 commit c236b43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/frontend/src/features/ReportActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export const ReportActions = forwardRef<HTMLDivElement, { report: ReportWithUser
data: {
...payload,
id: `report-${v4()}`,
title: `${report.title} - copie`,
title: `${report.title ?? "Sans titre"} - copie`,
createdAt: new Date(),
redactedBy: user.name,
redactedById: user.id,
createdBy: user.id,
pdf: undefined,
},
});
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/routes/edit.$reportId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ const WithReport = ({ report }: { report: Report }) => {

const user = useUser()!;
const isOwner = report.redactedById === user.id;
const isCreator = report.createdBy === user.id;

const userDelegations = useLiveQuery(
db.delegation.liveFirst({ where: { createdBy: report.createdBy, delegatedTo: user.id } }),
);

const hasDelegation = !!userDelegations.results;
const canEdit = isOwner || hasDelegation;
const canEdit = isOwner || isCreator || hasDelegation;

const navigate = useNavigate();

Expand Down

0 comments on commit c236b43

Please sign in to comment.