Skip to content
Alain Becam edited this page Aug 23, 2023 · 4 revisions

Add a new route and the corresponding controller method

In the controller, the method should be allowed first. There is 5 permissions groups, defined in /lib/seek/permissions/translator.rb :

MAP = {
 view: Set.new(%i[
                 view show index search favourite favourite_delete comment comment_delete comments
                 comments_timeline rate tag items statistics tag_suggestions preview runs
                 new_object_based_on_existing_one samples_table current
               ]).freeze,

 download: Set.new(%i[
                     download named_download launch submit_job data execute plot explore
                     download_log download_results input output download_output download_input
                     view_result compare_versions simulate diagram ro_crate
                   ]).freeze,

 edit: Set.new(%i[
                 edit new create update new_version create_version destroy_version edit_version
                 update_version new_item create_item edit_item update_item quick_add resolve_link
                 describe_ports retrieve_nels_sample_metadata
               ]).freeze,

 delete: Set.new(%i[
                   delete destroy destroy_item cancel destroy_samples_confirm
                 ]).freeze,

 manage: Set.new(%i[
                   manage manage_update notification read_interaction write_interaction report_problem storage_report
                   select_sample_type extraction_status extract_samples confirm_extraction cancel_extraction
                   upload_fulltext upload_pdf soft_delete_fulltext
                 ]).freeze
}.freeze

So if we want a new method edit_something, we would probably add it to the edit set.

But the element you work on might need to be approved as well (depending on the current user):

before_action :find_and_authorize_requested_item, only: %i[show edit manage update destroy download upload_fulltext upload_pdf soft_delete_fulltext]

So the method “update” for instance need to work on the current element (a publication in that case). Find_and_authorize_requested_item will automatically recover the publication (and so the associated variables) if allowed. If not allowed the publication will be null.

Add a setting

For instance for **allow_publications_fulltext:

First in config_setting_attributes.yml -> Name only

app -> Controllers

admin_controller.rb

In update_settings

Seek::Config.allow_publications_fulltext = string_to_boolean params[:allow_publications_fulltext]

views -> admin

settings.html.erb

<%= admin_checkbox_setting(:allow_publications_fulltext, 0, Seek::Config.allow_publications_fulltext,
                        "Allow uploading FullTexts", "Allow the registered users to upload Fulltext (pdf) for publications. They can also be made public. Please makes sure it is allowed first.") %>

config -> initializers

seek_configuration.rb-openseek

Seek::Config.default :allow_publications_fulltext,false

seek_testing.rb

For test the setting should be on, so we can test it!

Settings.defaults[:allow_publications_fulltext] = true

To use:

if Seek::Config.allow_publications_fulltext

In views:

<% if Seek::Config.allow_publications_fulltext %>

Localisation

Seek uses the standard i18n to localise. The main English localisation is config/locale/en.yml

  • There is an overload for test:/test/config/translation_override.en.yml that needs to be manually loaded, see for instance /test/functional/internationalization_test.rb. We use it for instance as the default local for Seek models, such as Project, have the exact same name, so we cannot know if the localisation works or not (it could use the default name).

  • Entries such as study: &study "Study"

Followed by entries like study: *study

The first line establishes an alias &study for the entry, the 2nd uses the alias, so get the same value.

  • Some variables can be added to an entry: tracking: "Cookies required for %{analytics}, to help SEEK improve its service."

It will be used like that: t("cookies.options.tracking", analytics: analytics_txt)

We gives the value as parameter.

It cannot be used within the localisation file for nested translation, i.e if you write that:

analytics: "my analytics"
tracking: "Cookies required for %{analytics}, to help SEEK improve its service."

tracking will not use the value of analytics. You would have to do it manually: t("cookies.options.tracking", analytics: t("cookies.options.analytics"))