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

Small fixes #3232

Merged
merged 7 commits into from
Dec 8, 2023
Merged

Small fixes #3232

merged 7 commits into from
Dec 8, 2023

Conversation

Macroz
Copy link
Collaborator

@Macroz Macroz commented Dec 4, 2023

Close #2880
Close #3230

  • Show organization in create workflow forms dropdown (was shown everwhere else)
  • Use localized "org" text. Could be further improved by localizing : and parens too.
  • Fixes warning in license view about lazy deref and missing key prop.
  • Fixes warning from :loading? attribute being passed to HTML where it has invalid meaning.
  • Also fixes copying another organization's form

image

Checklist for author

Remove items that aren't applicable, check items that are done.

Reviewability

  • Link to issue
  • Consider adding screenshots for ease of review

Documentation

  • Update changelog if necessary

Testing

  • Complex logic is unit tested
  • Valuable features are integration / browser / acceptance tested automatically

Follow-up

  • New tasks are created for pending or remaining tasks

This is for consistency, it is shown everywhere else.
Ideally we would use `text-format` so that the parens and colon would
come from the localization as well, but this is a clear improvement.
When copying a form, the copied form retains the organization (old)
and the user may not be member of it. If the organization is not
changed in the dropdown it used to persist and cause Forbidden
error. Now we verify that the organization of an item is valid, or
reset it otherwise. This allows user to select it after a simple
validation fail.
This caused warning e.g. when autosave happens on a freshly opened application.
Comment on lines 290 to +313
(defn organization-field [context {:keys [keys readonly on-change]}]
(let [label (text :t.administration/organization)
organizations @(rf/subscribe [:owned-organizations])
(let [id (keys-to-id keys)
label (text :t.administration/organization)
owned-organizations @(rf/subscribe [:owned-organizations])
valid-organizations (->> owned-organizations (filter :enabled) (remove :archived))
disallowed (roles/disallow-setting-organization? @(rf/subscribe [:roles]))
language @(rf/subscribe [:language])
form @(rf/subscribe [(:get-form context)])
value (get-in form keys)
potential-value (get-in form keys)
on-change (or on-change (fn [_]))
wrapped-on-change #(let [new-value %]
(rf/dispatch [(:update-form context) keys new-value])
(on-change new-value))

;; if item was copied then this org could be something old
;; where we have no access to so reset here
value (if (or readonly
disallowed
(contains? (set (mapv :organization/id valid-organizations))
(:organization/id potential-value)))
potential-value

;; not accessible, reset
(wrapped-on-change nil))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflecting on earlier discussion: i noticed that copy as new does fetch form template from API, and it got me thinking that would it make sense to include extra param and have API remove the disallowed organization? this could make UI code be less complected wrt. disallowed organization, although extra parameter smells a lot like backend for frontend. existing API would be unconcerned with it though.

related implementation thoughts:

;; new function in rems.service.form
(defn get-form-for-copy [form]
  (let [organization (rems.db.organizations/get-organization-by-id-raw
                      (get-in form [:organization :organization/id]))]
    (if (rems.service.util/may-edit-organization? organization)
      form
      (dissoc form :organization))))

;; amend rems.api.forms with query-params
(GET "/:form-id" []
  :summary "Get form by id"
  :roles +admin-read-roles+
  :path-params [form-id :- (describe s/Int "form-id")]
  :query-params [{copy :- (describe s/Bool "whether to format return value suitable for copy-as-new action") false}]
  :return schema/FormTemplate
  (if-let [form (form/get-form-template form-id)]
    (ok (cond-> form
          copy form/get-form-for-copy))
    (not-found-json-response)))

;; add query-param in rems.administration.create-form/enter-page event-fx fetcher
:dispatch-n [(when form-id [::form {:copy true}])] 

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there could be two different API endpoints, one for copy like /forms/123/copy, and choose which one to call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't have this kind of functionality in the API (copy), and it doesn't make as much sense in the API (you can just get the regular form and then do whatever in the client), I'm hesitant to add it like this. If it were a pure client action copy then it'd make sense, however that does not make the code any simpler. It just moves the logic to the fetcher, which maybe needs to have the subscription data injected to it because it's not a component.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds reasonable. here i don't see added value in moving more logic to fetcher, compared to doing filtering in organization component.

having a common way to filter domain objects in client, such that it is easy to present only e.g. own organization forms could be good for maintainability. this could be achieved by refactoring entities to use same patterns like [:organization :organization/id]. enriching API return values with ACL could provide similar benefits, however it is quite a bit heavier to implement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to unify the domain objects a bit first. And perhaps this filter can try first :organization/id and then :organization :organization/id somewhat automatically. That's basically what the pattern could be after unifying the domain objects a bit better.

@Macroz Macroz merged commit 170dfdf into master Dec 8, 2023
7 checks passed
@Macroz Macroz deleted the show-org-in-dropdown branch December 8, 2023 11:49
@Macroz Macroz added this to Done (newest on top) in Rems task board Dec 8, 2023
@meericsc meericsc moved this from Done (newest on top) to Accepted in Rems task board Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Unify display of org in dropdowns Copy another organization's form
2 participants