Skip to content

Commit

Permalink
fix(Project): state issue when changing project url
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Sep 17, 2024
1 parent ad158d6 commit d8ad4bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions client/src/components/projects/AdminChangeURL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import api from "../../api";
interface AdminChangeURLProps {
projectID: string;
currentURL?: string;
onSave: (newURL: string) => void;
onClose: () => void;
}

const AdminChangeURL: React.FC<AdminChangeURLProps> = ({ projectID, currentURL, onClose }) => {
const AdminChangeURL: React.FC<AdminChangeURLProps> = ({ projectID, currentURL, onSave, onClose }) => {
const { handleGlobalError } = useGlobalError();
const { addNotification } = useNotifications();
const { control, getValues, trigger, watch } = useForm<{ url: string }>({ defaultValues: { url: currentURL || "" } });
Expand All @@ -36,7 +37,7 @@ const AdminChangeURL: React.FC<AdminChangeURLProps> = ({ projectID, currentURL,
type: "success"
});

onClose();
onSave(url);
} catch (err) {
console.error(err);
handleGlobalError(err);
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/projects/ProjectPropertiesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ const ProjectPropertiesModal: React.FC<ProjectPropertiesModalProps> = ({
<AdminChangeURL
projectID={projectID}
currentURL={getValues("projectURL") as string}
onSave={(newURL) => {
setValue("projectURL", newURL);
closeAllModals();
}}
onClose={() => closeAllModals()}
/>
)
Expand Down
4 changes: 2 additions & 2 deletions server/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ async function updateProject(req, res) {
/* If the Project URL is a LibreTexts link, gather more information */

// If attempting to change a workbench project url, ensure user is a superadmin
const user = await User.findOne({ uuid: req.user.decoded.uuid }).lean();
if (!user || (project.didCreateWorkbench && user.roles.filter((role) => role.org === process.env.ORG_ID && role.role === 'superadmin').length === 0)) {
const isSuperadmin = req.user.roles?.filter((role) => role.org === process.env.ORG_ID && role.role === 'superadmin').length > 0;
if (project.didCreateWorkbench && !isSuperadmin) {
return res.status(403).send({
err: true,
errMsg: conductorErrors.err8,
Expand Down
2 changes: 1 addition & 1 deletion server/api/validators/central-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const VerificationStatusUpdateWebhookValidator = z.object({
export const CheckUserApplicationAccessValidator = z.object({
params: z.object({
id: z.string().uuid(),
applicationId: z.coerce.number().positive().int().or(z.literal('dev'))
applicationId: z.coerce.number().positive().int()
}),
});

Expand Down

0 comments on commit d8ad4bb

Please sign in to comment.