You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is pretty much done, in that the update action now supports setting approved: true on projects, and this change is only allowed by the policy if the user performing it is an admin.
defchangeset(struct,params)dostruct|>cast(params,[:approval_requested,:cloudinary_public_id,:default_color,:description,:long_description_markdown,:title,:website])|>prefix_url(:website)|>validate_format(:website,CodeCorps.Helpers.URL.valid_format())|>validate_required([:title])|>generate_slug(:title,:slug)|>validate_slug(:slug)|>unique_constraint(:slug,name: :index_projects_on_slug)# this throws a validation error on update|>check_constraint(:long_description_markdown,message: "cannot be deleted once your project is approved",name: "set_long_description_markdown_if_approved")|>MarkdownRendererService.render_markdown_to_html(:long_description_markdown,:long_description_body)end
The constraint is defined as
createconstraint(:projects,"set_long_description_markdown_if_approved",check: "long_description_markdown IS NOT NULL OR approved = false")
What happens is
during project creation, we do not validate long description as required
during project approval, approved is set to true, but the project has no long description, so on update, validation fails
We need to either
add validation to project creation
remove the constraint
add a way to notify the user as to why we can't approve
Adding a custom clause or subclause to Projects.update won't work, because the constraint is at db level, so will trigger in all cases.
Problem
EDIT: See the comment below.
We want to have a place for a
Project
to be explicitly approved by an admin.The text was updated successfully, but these errors were encountered: