diff --git a/app/models/user.rb b/app/models/user.rb index f02a1325..d32ad888 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,10 +3,10 @@ class User < ActiveRecord::Base # Virtual attribute for the unencrypted password attr_accessor :password - + has_many :memberships, :dependent => :destroy has_many :groups, :through => :memberships - + has_many :my_maps, :dependent => :destroy has_many :maps, :through => :my_maps, :uniq => true has_many :layers @@ -26,7 +26,7 @@ class User < ActiveRecord::Base has_many :permissions has_many :roles, :through => :permissions - + before_save :encrypt_password before_create :make_activation_code @@ -181,6 +181,10 @@ def has_role?(name) self.roles.find_by_name(name) ? true : false end + def nepa_admin? + has_role?("administrator") || has_role?("super user") + end + #outside of protected and private scope, so an admin can force activate a user def force_activate! @activated = true @@ -215,7 +219,7 @@ def make_password_reset_code self.password_reset_code = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join ) end - + private def activate! diff --git a/app/views/nepa_documents/index.html.erb b/app/views/nepa_documents/index.html.erb index 42728425..0205d58c 100644 --- a/app/views/nepa_documents/index.html.erb +++ b/app/views/nepa_documents/index.html.erb @@ -48,7 +48,7 @@ link_to 'View Associated Map', map_path(nepa_document.map_id), :class => "btn btn-default", :role => "button" else - if current_user.has_role?("administrator") || current_user.has_role?("super user") + if logged_in? && current_user.nepa_admin? #link_to "Assign to Map", assign_nepa_document_path(nepa_document) link_to "Assign to Project Map", {:controller => 'maps', :action =>'nepaproject', :nepa => "assign", :doc => nepa_document.id}, :class => "btn btn-default", :role => "button" end @@ -56,8 +56,8 @@ end %> -
<%= link_to 'New NEPA Document', new_nepa_document_path, :class => "btn btn-default", :role => "button" %>
<% end %> diff --git a/app/views/nepa_documents/show.html.erb b/app/views/nepa_documents/show.html.erb index b2ffe597..d9b01ed1 100644 --- a/app/views/nepa_documents/show.html.erb +++ b/app/views/nepa_documents/show.html.erb @@ -37,13 +37,13 @@ <%= link_to "View NEPA Milestones", nepa_document_nepa_milestones_path(@nepa_document), :class => "btn btn-default", :role => "button" %> -<% if current_user.has_role?("administrator") || current_user.has_role?("super user") %> +<% if logged_in? && current_user.nepa_admin? %> <%= link_to 'Edit this NEPA Document', edit_nepa_document_path(@nepa_document), :class => "btn btn-default", :role => "button" %> <% end %> <%= if @nepa_document.map_id.nil? - if current_user.has_role?("administrator") || current_user.has_role?("super user") + if logged_in? && current_user.nepa_admin? link_to "Assign to Map", assign_nepa_document_path(@nepa_document), :class => "btn btn-default", :role => "button" end else diff --git a/app/views/nepa_milestones/index.html.erb b/app/views/nepa_milestones/index.html.erb index b93d606d..51c4e63c 100644 --- a/app/views/nepa_milestones/index.html.erb +++ b/app/views/nepa_milestones/index.html.erb @@ -16,15 +16,16 @@