Resourcified roles.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8145 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2011-12-09 23:29:58 +00:00
parent b127f9157d
commit 532a76f78c
10 changed files with 82 additions and 57 deletions
+23 -9
View File
@@ -19,9 +19,8 @@ class RolesController < ApplicationController
layout 'admin'
before_filter :require_admin
before_filter :find_role, :only => [:edit, :update, :destroy]
verify :method => :post, :only => [ :destroy ],
:redirect_to => { :action => :index }
def index
@role_pages, @roles = paginate :roles, :per_page => 25, :order => 'builtin, position'
@@ -31,6 +30,11 @@ class RolesController < ApplicationController
def new
# Prefills the form with 'Non member' role permissions
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
@roles = Role.all
end
def create
@role = Role.new(params[:role])
if request.post? && @role.save
# workflow copy
if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
@@ -39,23 +43,25 @@ class RolesController < ApplicationController
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index'
else
@permissions = @role.setable_permissions
@roles = Role.find :all, :order => 'builtin, position'
@roles = Role.all
render :action => 'new'
end
end
def edit
@role = Role.find(params[:id])
if request.post? and @role.update_attributes(params[:role])
end
def update
if request.put? and @role.update_attributes(params[:role])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index'
else
@permissions = @role.setable_permissions
render :action => 'edit'
end
end
verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
def destroy
@role = Role.find(params[:id])
@role.destroy
redirect_to :action => 'index'
rescue
@@ -63,7 +69,7 @@ class RolesController < ApplicationController
redirect_to :action => 'index'
end
def report
def permissions
@roles = Role.find(:all, :order => 'builtin, position')
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
if request.post?
@@ -75,4 +81,12 @@ class RolesController < ApplicationController
redirect_to :action => 'index'
end
end
private
def find_role
@role = Role.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
end
+1
View File
@@ -26,6 +26,7 @@ class Role < ActiveRecord::Base
['own', :label_issues_visibility_own]
]
default_scope :order => 'builtin, position'
named_scope :givable, { :conditions => "builtin = 0", :order => 'position' }
named_scope :builtin, lambda { |*args|
compare = 'not' if args.first == true
+1 -1
View File
@@ -14,7 +14,7 @@
<h3><%= l(:label_permissions) %></h3>
<div class="box tabular" id="permissions">
<% perms_by_module = @permissions.group_by {|p| p.project_module.to_s} %>
<% perms_by_module = @role.setable_permissions.group_by {|p| p.project_module.to_s} %>
<% perms_by_module.keys.sort.each do |mod| %>
<fieldset><legend><%= mod.blank? ? l(:label_project) : l_or_humanize(mod, :prefix => 'project_module_') %></legend>
<% perms_by_module[mod].each do |permission| %>
+2 -2
View File
@@ -1,6 +1,6 @@
<h2><%= link_to l(:label_role_plural), :controller => 'roles', :action => 'index' %> &#187; <%=h @role.name %></h2>
<h2><%= link_to l(:label_role_plural), roles_path %> &#187; <%=h @role.name %></h2>
<% labelled_form_for :role, @role, :url => { :action => 'edit' }, :html => {:id => 'role_form'} do |f| %>
<% labelled_form_for @role do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<% end %>
+6 -6
View File
@@ -1,5 +1,5 @@
<div class="contextual">
<%= link_to l(:label_role_new), {:action => 'new'}, :class => 'icon icon-add' %>
<%= link_to l(:label_role_new), new_role_path, :class => 'icon icon-add' %>
</div>
<h2><%=l(:label_role_plural)%></h2>
@@ -13,15 +13,15 @@
<tbody>
<% for role in @roles %>
<tr class="<%= cycle("odd", "even") %>">
<td><%= content_tag(role.builtin? ? 'em' : 'span', link_to(h(role.name), :action => 'edit', :id => role)) %></td>
<td><%= content_tag(role.builtin? ? 'em' : 'span', link_to(h(role.name), edit_role_path(role))) %></td>
<td align="center" style="width:15%;">
<% unless role.builtin? %>
<%= reorder_links('role', {:action => 'edit', :id => role}) %>
<%= reorder_links('role', {:action => 'update', :id => role}, :put) %>
<% end %>
</td>
<td class="buttons">
<%= link_to(l(:button_delete), { :action => 'destroy', :id => role },
:method => :post,
<%= link_to(l(:button_delete), role_path(role),
:method => :delete,
:confirm => l(:text_are_you_sure),
:class => 'icon icon-del') unless role.builtin? %>
</td>
@@ -32,6 +32,6 @@
<p class="pagination"><%= pagination_links_full @role_pages %></p>
<p><%= link_to l(:label_permissions_report), :action => 'report' %></p>
<p><%= link_to l(:label_permissions_report), :action => 'permissions' %></p>
<% html_title(l(:label_role_plural)) -%>
+2 -2
View File
@@ -1,6 +1,6 @@
<h2><%= link_to l(:label_role_plural), :controller => 'roles', :action => 'index' %> &#187; <%=l(:label_role_new)%></h2>
<h2><%= link_to l(:label_role_plural), roles_path %> &#187; <%=l(:label_role_new)%></h2>
<% labelled_form_for :role, @role, :url => { :action => 'new' }, :html => {:id => 'role_form'} do |f| %>
<% labelled_form_for @role do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<% end %>
@@ -1,6 +1,6 @@
<h2><%= link_to l(:label_role_plural), :controller => 'roles', :action => 'index' %> &#187; <%=l(:label_permissions_report)%></h2>
<h2><%= link_to l(:label_role_plural), roles_path %> &#187; <%=l(:label_permissions_report)%></h2>
<% form_tag({:action => 'report'}, :id => 'permissions_form') do %>
<% form_tag(permissions_roles_path, :id => 'permissions_form') do %>
<%= hidden_field_tag 'permissions[0]', '', :id => nil %>
<div class="autoscroll">
<table class="list">