diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index 2d121b7..6dd93f7 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -1,6 +1,7 @@ class OrganisationsController < ApplicationController after_action :verify_authorized + ## # GET /organisations/1 def admin_show @organisation = Org.find(params[:id]) @@ -10,15 +11,15 @@ end end - # GET /organisations/1/edit + ## + # GET /organisations/1/edit def admin_edit @organisation = Org.find(params[:id]) authorize @organisation - @languages = Language.all.order("name") end - + ## # PUT /organisations/1 def admin_update @organisation = Org.find(params[:id]) @@ -28,7 +29,7 @@ assign_params = params[:organisation].dup assign_params.delete(:logo) assign_params.delete(:contact_email) unless params[:organisation][:contact_email].present? - + respond_to do |format| begin if @organisation.update_attributes(assign_params) @@ -37,55 +38,10 @@ flash[:noice] = @organisation.errors.collect{|e| e.message}.join('
').html_safe format.html { render action: "admin_edit" } end - rescue Dragonfly::Job::Fetch::NotFound => dflye flash[:notice] = I18n.t("admin.org_bad_logo") format.html {render action: "admin_edit"} end end end - - #TODO: see if this is used by the ajax... otherwise lock it down - def parent - @organisation = Org.find(params[:id]) - authorize @organisation - parent_org = @organisation.find_by {|o| o.parent_id } - return parent_org - end - - #TODO: see is this is used by the ajax... otherwise lock it down - def children - @organisation = Org.find(params[:id]) - authorize @organisation - #if user_signed_in? then - children = {} - @organisation.children.each do |child| - children[child.id] = child.name - end - respond_to do |format| - format.json { render json: children.to_json } - end -# else -# render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) -# end - end - - #TODO: see if this is used by the ajax... otherwise lock it down - def templates - @organisation = Org.find(params[:id]) - authorize @organisation - #if user_signed_in? then - templates = {} - @organisation.dmptemplates.each do |template| - if template.is_published? then - templates[template.id] = template.title - end - end - respond_to do |format| - format.json { render json: templates.to_json } - end -# else -# render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) -# end - end end diff --git a/app/policies/org_policy.rb b/app/policies/org_policy.rb new file mode 100644 index 0000000..311d389 --- /dev/null +++ b/app/policies/org_policy.rb @@ -0,0 +1,34 @@ +class OrgPolicy < ApplicationPolicy + attr_reader :user, :org + + def initialize(user, org) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @org = org + end + + def admin_show? + user.can_modify_org_details? && (user.org_id == org.id) + end + + def admin_edit? + user.can_modify_org_details? && (user.org_id == org.id) + end + + def admin_update? + user.can_modify_org_details? && (user.org_id == org.id) + end + + def parent? + true + end + + def children? + true + end + + def templates? + true + end + +end \ No newline at end of file diff --git a/app/policies/organisation_policy.rb b/app/policies/organisation_policy.rb deleted file mode 100644 index 8fb3bb2..0000000 --- a/app/policies/organisation_policy.rb +++ /dev/null @@ -1,34 +0,0 @@ -class OrganisationPolicy < ApplicationPolicy - attr_reader :user, :organisation - - def initialize(user, organisation) - raise Pundit::NotAuthorizedError, "must be logged in" unless user - @user = user - @organisation = organisation - end - - def admin_show? - user.can_modify_org_details? && (user.organisation.id == organisation.id) - end - - def admin_edit? - user.can_modify_org_details? && (user.organisation.id == organisation.id) - end - - def admin_update? - user.can_modify_org_details? && (user.organisation.id == organisation.id) - end - - def parent? - true - end - - def children? - true - end - - def templates? - true - end - -end \ No newline at end of file diff --git a/app/views/organisations/admin_edit.html.erb b/app/views/organisations/admin_edit.html.erb deleted file mode 100644 index 9a2548c..0000000 --- a/app/views/organisations/admin_edit.html.erb +++ /dev/null @@ -1,85 +0,0 @@ -<%= stylesheet_link_tag "admin" %> -<% javascript 'admin.js' %> - -

- <%= t('org_admin.org_details_label') %> -

- -
- -
- <%= form_for(@organisation, :url => admin_update_organisation_path(@organisation), :html => { :multipart => true, :id => "edit_org_details", :method => :put}) do |f| %> - - - - - - - - - - - - - - - <% if @organisation.logo.present? %> - - - - - - - - - <%end%> - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%= t('org_admin.org_name') %><%= f.text_field :name, :as => :string, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.name_help_text') %>
<%= t('org_admin.org_abbr') %> -
- <%= f.text_field :abbreviation, :as => :string, :class => 'text_field' %> -
-
-
<%= t('org_admin.org_logo') %><%= image_tag @organisation.logo.url %>
<%= f.check_box :remove_logo %>   <%= t('org_admin.remove_logo') %>
<%= t('org_admin.new_org_logo') %><%= f.file_field :logo %>
<%= t('org_admin.org_banner_text') %><%= text_area_tag("org_banner_text", @organisation.banner_text, class: "tinymce") %>
<%= t('org_admin.org_target_url') %><%= f.text_field :target_url, :as => :string, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.target_url_help_text') %>
<%= t('org_admin.org_contact_email') %><%= f.text_field :contact_email, :as => :string, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.org_contact_email_help_text') %>
<%= t('org_admin.org_type') %> - <%= @organisation.organisation_type.name %> -
- -
- - -
- <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn btn-primary' %> -
- <% end %> - -
-
- -<%= tinymce :content_css => asset_path('application.css') %> - diff --git a/app/views/organisations/admin_show.html.erb b/app/views/organisations/admin_show.html.erb deleted file mode 100644 index f853368..0000000 --- a/app/views/organisations/admin_show.html.erb +++ /dev/null @@ -1,78 +0,0 @@ -<%= stylesheet_link_tag "admin" %> - -

- <%= t('org_admin.org_details_label') %> -

-<%= t('org_admin.org_text')%> -
-
- -
- -
- - - - <% if @organisation.name.present? then%> - - - - - <% if @organisation.logo.present? then%> - - <%end%> - - <%end%> - <% if @organisation.abbreviation.present? then%> - - - - - <%end%> - <% if @organisation.banner_text.present? then%> - - - - - <%end%> - <% if @organisation.target_url.present? then%> - - - - - <%end%> - <% if @organisation.contact_email.present? then%> - - - - - <%end%> - <% if @organisation.organisation_type_id.present? then%> - - - - - <%end%> - <% if @organisation.parent_id.present? then%> - - - - - <%end%> - - - - -
<%= t('org_admin.org_name') %><%= @organisation.name %>
<%= t('org_admin.org_abbr') %><%= @organisation.abbreviation %>
<%= t('org_admin.org_banner_text') %><%= raw @organisation.banner_text %>
<%= t('org_admin.org_target_url') %><%= @organisation.target_url %>
<%= t('org_admin.org_contact_email') %><%= @organisation.contact_email %>
<%= t('org_admin.org_type') %><%= @organisation.organisation_type.name %>
<%= t('org_admin.parent_org') %><%= @organisation.parent.name %>
<%= t('org_admin.last_updated') %><%= l @organisation.updated_at.to_date, :formats => :short %>
- -
-
- -
- <%= link_to t("helpers.submit.edit"), admin_edit_organisation_path(current_user.organisation), :class => 'btn btn-primary'%> -
-
-
-
\ No newline at end of file diff --git a/app/views/orgs/admin_edit.html.erb b/app/views/orgs/admin_edit.html.erb new file mode 100644 index 0000000..3f6ab58 --- /dev/null +++ b/app/views/orgs/admin_edit.html.erb @@ -0,0 +1,97 @@ +<%= stylesheet_link_tag "admin" %> +<% javascript 'admin.js' %> + +

+ <%= t('org_admin.org_details_label') %> +

+ +
+ +
+ <%= form_for(@organisation, url: admin_update_organisation_path(@organisation), html: { multipart: true, id: "edit_org_details", method: :put}) do |f| %> + + + + + + + + + + + + + + + <% if @organisation.logo.present? %> + + + + + + + + + <%end%> + + + + + + + + + + + + + + + + + + + + + + + + + + + <% elsif @organisation.funder? %> + + <% elsif @organisation.organisation? %> + + <% elsif @organisation.research_institute? %> + + <% elsif @organisation.project? %> + + <% elsif @organisation.school? %> + + <% end %> + + +
<%= t('org_admin.org_name') %><%= f.text_field :name, as: :string, class: 'text_field has-tooltip', data_toggle: "tooltip", title: t('org_admin.name_help_text') %>
<%= t('org_admin.org_abbr') %> +
+ <%= f.text_field :abbreviation, as: :string, class: 'text_field' %> +
+
+
<%= t('org_admin.org_logo') %><%= image_tag @organisation.logo.url %>
<%= f.check_box :remove_logo %>   <%= t('org_admin.remove_logo') %>
<%= t('org_admin.new_org_logo') %><%= f.file_field :logo %>
<%= t('org_admin.org_banner_text') %><%= text_area_tag("org_banner_text", @organisation.banner_text, class: "tinymce") %>
<%= t('org_admin.org_target_url') %><%= f.text_field :target_url, as: :string, class: 'text_field has-tooltip', data_toggle: "tooltip", :title t('org_admin.target_url_help_text') %>
<%= t('org_admin.org_contact_email') %><%= f.text_field :contact_email, as: :string, class: 'text_field has-tooltip', data_toggle: "tooltip", title: t('org_admin.org_contact_email_help_text') %>
<%= t('org_admin.org_type') %> + <% if @organisation.institution? %> + <%= "Institution" %><%= "Funder" %><%= "Organisation" %><%= "Research Institute" %><%= "Project" %><%= "School" %>
+ +
+ + +
+ <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn btn-primary' %> +
+ <% end %> + +
+
+ +<%= tinymce content_css: asset_path('application.css') %> + diff --git a/app/views/orgs/admin_show.html.erb b/app/views/orgs/admin_show.html.erb new file mode 100644 index 0000000..43fda59 --- /dev/null +++ b/app/views/orgs/admin_show.html.erb @@ -0,0 +1,94 @@ +<%= stylesheet_link_tag "admin" %> + +

+ <%= t('org_admin.org_details_label') %> +

+<%= t('org_admin.org_text')%> +
+
+
+ +
+ + + + <% if @organisation.name.present? then %> + + + + + <% if @organisation.logo.present? then %> + + <% end %> + + <% end %> + + <% if @organisation.abbreviation.present? then %> + + + + + <% end %> + + <% if @organisation.banner_text.present? then %> + + + + + <% end %> + + <% if @organisation.target_url.present? then %> + + + + + <% end %> + + <% if @organisation.contact_email.present? then %> + + + + + <% end %> + + <% if @organisation.org_type != 0 then %> + + + <% if @organisation.institution? %> + + <% elsif @organisation.funder? %> + + <% elsif @organisation.organisation? %> + + <% elsif @organisation.research_institute? %> + + <% elsif @organisation.project? %> + + <% elsif @organisation.school? %> + + <% end %> + + <% end %> + + <% if @organisation.parent_id.present? then %> + + + + + <% end %> + + + + + +
<%= t('org_admin.org_name') %><%= @organisation.name %>
<%= t('org_admin.org_abbr') %><%= @organisation.abbreviation %>
<%= t('org_admin.org_banner_text') %><%= raw @organisation.banner_text %>
<%= t('org_admin.org_target_url') %><%= @organisation.target_url %>
<%= t('org_admin.org_contact_email') %><%= @organisation.contact_email %>
<%= t('org_admin.org_type') %><%= "Institution" %><%= "Funder" %><%= "Organisation" %><%= "Research Institute" %><%= "Project" %><%= "School" %>
<%= t('org_admin.parent_org') %><%= @organisation.parent.name %>
<%= t('org_admin.last_updated') %><%= l @organisation.updated_at.to_date, :formats => :short %>
+ +
+
+ +
+ <%= link_to t("helpers.submit.edit"), admin_edit_organisation_path(current_user.organisation), :class => 'btn btn-primary'%> +
+
+
+
\ No newline at end of file