diff --git a/app/assets/stylesheets/observations.scss b/app/assets/stylesheets/observations.scss index 8de8d91e..0c323a0c 100644 --- a/app/assets/stylesheets/observations.scss +++ b/app/assets/stylesheets/observations.scss @@ -5,3 +5,15 @@ margin-bottom: 10px; } } + +.column.title-publish { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 2rem; + margin-bottom: 1rem; + + h3 { + margin: 0; + } +} diff --git a/app/controllers/observations_controller.rb b/app/controllers/observations_controller.rb index ac7c3350..b262f748 100644 --- a/app/controllers/observations_controller.rb +++ b/app/controllers/observations_controller.rb @@ -71,6 +71,13 @@ def destroy end end + def toggle_publish_state + @observation = Observation.find params[:id] + authorize @observation + @observation.toggle_publish_state + redirect_to @observation.import + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/app/models/observation.rb b/app/models/observation.rb index 578b10e9..aa09dd2a 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -47,4 +47,12 @@ def title [species_names, references_names].reject(&:blank?).join(" - ") end + + def published? + !hidden? + end + + def toggle_publish_state + update(hidden: !hidden?) + end end diff --git a/app/policies/observation_policy.rb b/app/policies/observation_policy.rb index 9293605e..e77b026e 100644 --- a/app/policies/observation_policy.rb +++ b/app/policies/observation_policy.rb @@ -23,6 +23,10 @@ def destroy? user.admin? end + def toggle_publish_state? + user.admin? || record.import&.user == user + end + class Scope < Scope def resolve if user&.admin? diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb index bb184d72..1ab9314a 100644 --- a/app/views/imports/show.html.erb +++ b/app/views/imports/show.html.erb @@ -156,8 +156,9 @@ <% @import.observations.each do |observation| %>
Choice to embargo data. If checked then data will be hidden from main daptabase. Can be released by an administrator.
+Choice to embargo data. If checked then data will be hidden from main database. Can be released by an administrator.