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

Fix long description validation #1263

Open
joshsmith opened this issue Nov 28, 2017 · 1 comment
Open

Fix long description validation #1263

joshsmith opened this issue Nov 28, 2017 · 1 comment

Comments

@joshsmith
Copy link
Contributor

joshsmith commented Nov 28, 2017

Problem

EDIT: See the comment below.

We want to have a place for a Project to be explicitly approved by an admin.

@begedin
Copy link
Contributor

begedin commented Dec 5, 2017

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.

The one thing we need to deal with, and this is a difficulty I've encountered while working on code-corps/code-corps-ember#1576

def changeset(struct, params) do
  struct
  |> 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

create constraint(
  :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.

@joshsmith joshsmith changed the title Add admin approval of a project Fix long description validation Jan 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants