Check precondition before/during displaying a form

What’s the best way to check a precondition before or during the display of an interactive app menu/launcher/form. For example, checking if a user is in a group, a app or directory exists, etc – then displaying an message like, “You are not set up for this app. Please contact admins”.

Hi Lopaka.

Thanks for your question.

I’ll take a stab at it. @jeff.ohrstrom or @travert may have a better solution.

The forms for the apps can contain ruby code. You would need to ensure the form is named with the .erb extension.

Here’s an example for getting the groups.

<%-
  groups = OodSupport::User.new.groups.sort_by(&:id).tap { |groups|
    groups.unshift(groups.delete(OodSupport::Process.group))
  }.map(&:name).grep(/^P./)
-%>

Hope this helps.

-gerald

You could control access through file permissions. If the user isn’t in a group, they simply won’t even see the app to begin with.

https://osc.github.io/ood-documentation/latest/app-sharing.html#system-installed-apps

Checking for a directory would be tougher. You’d have to probably write something to the HTML through a hidden field in you form. At that point you’d have to write javascript to interpret the value and alert.

It’s going to be much easier to edit the submit.yml.erb and check for the directory before the we submit the job to the scheduler. The message you raise will be displayed to the user.

<%- 
  dir = '/the/path/to/the/dir'
  raise StandardError, "you can't do that" unless Dir.exist?(dir)
-%>

Can you elaborate on the directory existing requirement you’d have for your users?

Gerald and Jeff, this solves 3 problems I had! Thanks for the info.

On this front, I think the submit.yml.erb method is the best – I’d like to keep the app visible so folks know it’s available, but then error out.

This is for a per-user install of Galaxy in ~/opt/galaxy which launches using a batch connect app.

Works fine so far. Does require a custom config galaxy.yml file to be generated in before.sh.erb and a timeout wait in after.sh for galaxy’s long startup process.

-Lopaka