summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-09 23:29:58 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-09 23:29:58 +0000
commit532a76f78c917d4391f4a8ecce9f8201b041d57d (patch)
tree184c676eaf6f1a867ac47197f5722a272d76858b /app
parentb127f9157d456f233b320b349b415844eb632cb9 (diff)
downloadredmine-532a76f78c917d4391f4a8ecce9f8201b041d57d.tar.gz
redmine-532a76f78c917d4391f4a8ecce9f8201b041d57d.zip
Resourcified roles.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8145 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/roles_controller.rb32
-rw-r--r--app/models/role.rb1
-rw-r--r--app/views/roles/_form.html.erb2
-rw-r--r--app/views/roles/edit.html.erb4
-rw-r--r--app/views/roles/index.html.erb12
-rw-r--r--app/views/roles/new.html.erb4
-rw-r--r--app/views/roles/permissions.html.erb (renamed from app/views/roles/report.html.erb)4
7 files changed, 37 insertions, 22 deletions
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb
index c0713cb82..b74404470 100644
--- a/app/controllers/roles_controller.rb
+++ b/app/controllers/roles_controller.rb
@@ -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
diff --git a/app/models/role.rb b/app/models/role.rb
index 9d9d8ae94..e0c0fef1c 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -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
diff --git a/app/views/roles/_form.html.erb b/app/views/roles/_form.html.erb
index 17b012313..45f8b0d86 100644
--- a/app/views/roles/_form.html.erb
+++ b/app/views/roles/_form.html.erb
@@ -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| %>
diff --git a/app/views/roles/edit.html.erb b/app/views/roles/edit.html.erb
index 2b1bd793b..3bb07c08f 100644
--- a/app/views/roles/edit.html.erb
+++ b/app/views/roles/edit.html.erb
@@ -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 %>
diff --git a/app/views/roles/index.html.erb b/app/views/roles/index.html.erb
index 3edd4672d..9d3c46c14 100644
--- a/app/views/roles/index.html.erb
+++ b/app/views/roles/index.html.erb
@@ -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)) -%>
diff --git a/app/views/roles/new.html.erb b/app/views/roles/new.html.erb
index f6a872cb2..77f31a7c0 100644
--- a/app/views/roles/new.html.erb
+++ b/app/views/roles/new.html.erb
@@ -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 %>
diff --git a/app/views/roles/report.html.erb b/app/views/roles/permissions.html.erb
index 052f7e267..32703e791 100644
--- a/app/views/roles/report.html.erb
+++ b/app/views/roles/permissions.html.erb
@@ -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">