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 %> - <% if current_user.has_role?("administrator") || current_user.has_role?("super user") %><%= link_to 'Edit', edit_nepa_document_path(nepa_document), :class => "btn btn-default", :role => "button" %><% end %> - <% if current_user.has_role?("administrator") || current_user.has_role?("super user") %><%= link_to 'Destroy', nepa_document, :confirm => 'Are you sure?', :method => :delete, :class => "btn btn-default", :role => "button" %><% end %> + <% if logged_in? && current_user.nepa_admin? %><%= link_to 'Edit', edit_nepa_document_path(nepa_document), :class => "btn btn-default", :role => "button" %><% end %> + <% if logged_in? && current_user.nepa_admin? %><%= link_to 'Destroy', nepa_document, :confirm => 'Are you sure?', :method => :delete, :class => "btn btn-default", :role => "button" %><% end %> @@ -73,7 +73,7 @@ <%= page_entries_info @nepa_documents %>. <%= select_tag :per_page, options_for_select([10,20,50,100], @per_page.to_i), :onchange => "if(this.value){reload_with_page(this.value)};" %> per page. -<% if current_user.has_role?("administrator") || current_user.has_role?("super user") %> +<% if logged_in? && current_user.nepa_admin? %>

<%= 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 @@ - <% #= nepa_milestone.milestone_type %> - <%= nepa_milestone.nepa_lookup_milestone.milestone %> + + (<%= nepa_milestone.milestone_type %>)  + <%= nepa_milestone.nepa_lookup_milestone ? nepa_milestone.nepa_lookup_milestone.milestone : "[DNE]" %> <%= nepa_milestone.actual_start_date.try(:strftime, '%m/%d/%Y') %> <%= nepa_milestone.actual_completion_date.try(:strftime, '%m/%d/%Y') %> <%= link_to 'View', nepa_document_nepa_milestone_path(@nepa_document, nepa_milestone), :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', edit_nepa_document_nepa_milestone_path(@nepa_document, nepa_milestone), :class => "btn btn-default", :role => "button" %> <%= link_to 'Delete', nepa_document_nepa_milestone_path(nepa_milestone.nepa_document_id, nepa_milestone.id), :method => :delete, :class => "btn btn-default", :role => "button" %> <% end %> @@ -34,7 +35,7 @@ -<% if current_user.has_role?("administrator") || current_user.has_role?("super user") %> +<% if logged_in? && current_user.nepa_admin? %> <%= link_to 'Add Milestone', new_nepa_document_nepa_milestone_path, :class => "btn btn-default", :role => "button" %> <% end %> diff --git a/app/views/nepa_milestones/show.html.erb b/app/views/nepa_milestones/show.html.erb index 0299b3f4..eb778fef 100644 --- a/app/views/nepa_milestones/show.html.erb +++ b/app/views/nepa_milestones/show.html.erb @@ -28,7 +28,7 @@ -<% if current_user.has_role?("administrator") || current_user.has_role?("super user") %> +<% if logged_in? && current_user.nepa_admin? %> <%= link_to 'Edit', edit_nepa_document_nepa_milestone_path(@nepa_document, @nepa_milestone), :class => "btn btn-default", :role => "button" %> <% end %> <%= link_to 'Back to Viewing all Milestones', nepa_document_nepa_milestones_path, :class => "btn btn-default", :role => "button" %>