rubyforgood / casa

Volunteer management system for nonprofit CASA, which serves foster youth in counties across America.
https://casavolunteertracking.org/
MIT License
307 stars 473 forks source link

Bug: Case Contact Contact Type Selection #5605

Open elasticspoon opened 6 months ago

elasticspoon commented 6 months ago

Can create contact types on a case contact that should not be allowed on it.

Steps: Volunteer manages cases A and B. Case A => Restrict contact types to just Casa Case B => Restrict contact types to just Judge.

As volunteer go to page for Case A, create new case contact. Available cases will be A and B with only A selected. Available contact types will be Casa and Judge.

Select Judge, complete form.

Case contact now has a contact type if should have been restricted from having. If you go to edit page for that case contact the contact type will not appear but it is on the record.

CaseContact.find(case_id).contact_types will include Judge.

https://www.loom.com/share/434f152958a5440c8bce9830c4c6f3b9?sid=bdf91748-7e24-4c47-9b71-098b8c91a83d

Possible Solutions / Considerations

mgrigoriev8109 commented 6 months ago

Can I grab this?

schoork commented 5 months ago

This seems pretty complex cause you're not going to want to break the existing behavior if the form allows you to select both.

compwron commented 5 months ago

probably js make sure to write tests!

github-actions[bot] commented 3 months ago

This issue has been open without changes for a long time! What's up?

thejonroberts commented 6 days ago

I looked at this a bit during Case Contact Form Overhaul - current code is:

def get_contact_types
    case_contact_types = ContactType.includes(:contact_type_group)
      .joins(:casa_case_contact_types)
      .active
      .where(casa_case_contact_types: {casa_case_id: @casa_cases.pluck(:id)})

    if case_contact_types.present?
      case_contact_types
    else
      ContactType
        .includes(:contact_type_group)
        .joins(:contact_type_group)
        .active
        .where(contact_type_group: {casa_org: current_organization})
        .order("contact_type_group.name ASC", :name)
    end
  end

This should handle when the types are restricted for one of the cases -- even when there are other cases available in the selection... I may be wrong, I don't think it's tested. May want to start with view specs for which types are shown.