alphagov/whitehall — pull request #104 by h-lame (2012-12-17 13:46:20+00:00)
Title: Lead organisations on documents

UI is now present to allow setting organisations as lead for a document. We present a list of organisations to choose as lead, and another list of organisations to choose as supporting. Order is determined by the list, if you want to reorder you have to manually choose the org you want in it's new position and then replace it with something else in it's new position. The lists are (arbitrarily) limited to 5 lead orgs and 7 supporting orgs. This could be changed via something like the js-duplicate-fields functionality we already have (but we'd have to tweak it). Validation requires that an edition has at least one lead organisation and that the same organisation isn't associated with the edition multiple times.

The Edition now has lead_edition_organisations and supporting_edition_organisations associations that use conditions to scope the existing edition_organisations association. There are methods rather than through associations for lead_organisations and supporting_organisations (because of the default_scope on organisations). The validations and controller code to cope with this is somewhat complex (for instance, in some places we deal with lead_edition_organisations if the object is ok, but edition_organisations if the object has errors).

I'm not sure there's an easy way to have 3 associations that scope to the same underlying table (1 unscoped, and 2 that scope in different ways) and and not end up with problems. It may make sense to remove the edition_organisations and organisations associations and always use lead_edition_organisations or supporting_edition_organisations.

Would appreciate comments.