Changed the link on the product details page to point to the
roles url beneath the product page itself.
From the user page, you can view the user's roles.
From the user's roles, you can go to the product to view the
other product
members.
From the product's member page, you can select any member and
view their other roles.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/roles_controller.rb | 16 ++++--
app/controllers/users_controller.rb | 10 +++-
app/views/products/show.html.erb | 2 +-
app/views/roles/_list.html.erb | 85 ++++++++++++++++++++++++++++++
app/views/roles/index.html.erb | 44 +---------------
app/views/users/_list.html.erb | 2 +-
app/views/users/roles.html.erb | 2 +
config/routes.rb | 4 +-
test/functional/users_controller_test.rb | 15 +++++
9 files changed, 127 insertions(+), 53 deletions(-)
create mode 100644 app/views/roles/_list.html.erb
create mode 100644 app/views/users/roles.html.erb
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb
index a768094..51fdbd5 100644
--- a/app/controllers/roles_controller.rb
+++ b/app/controllers/roles_controller.rb
@@ -27,13 +27,17 @@ class RolesController < ApplicationController
def index
@title = "#{(a)product.name} Members"
if @product.can_approve_roles?(@user)
- @product_roles = ProductRole.find_all_by_product_id(@product, :order =>
'role_id ASC')
+ @product_roles = ProductRole.paginate(
+ :conditions => ['product_id = ?', @product.id],
+ :order => 'role_id ASC',
+ :page => params[:page],
+ :per_page => 10)
else
- @product_roles = ProductRole.find_all_by_product_id(
- @product,
- :order => 'role_id ASC',
- :conditions => 'is_approved = true'
- )
+ @product_roles = ProductRole.paginate(
+ :conditions => ['product_id = ? and is_approved = true',
@product.id],
+ :order => 'role_id ASC',
+ :page => params[:page],
+ :per_page => 10)
end
respond_to do |format|
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 76c5525..1c58dbf 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -16,7 +16,7 @@
# +UsersController+ allows for CRUD operations on instances of +User+.
class UsersController < ApplicationController
- before_filter :authenticated, :except => [:index, :show, :new, :create, :backlog]
+ before_filter :authenticated, :except => [:index, :show, :new, :create, :backlog,
:roles]
before_filter :load_this_user, :except => [:index, :new, :create]
# GET /users
@@ -143,6 +143,14 @@ class UsersController < ApplicationController
end
end
+ # GET /users/1/roles
+ def roles
+ @product_roles = ProductRole.paginate(
+ :conditions => ['user_id = ?', @this_user.id],
+ :page => params[:page],
+ :per_page => 10)
+ end
+
private
def load_this_user
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb
index cf4bcd9..66ad0bb 100644
--- a/app/views/products/show.html.erb
+++ b/app/views/products/show.html.erb
@@ -34,7 +34,7 @@
<td class="label">Members:</td>
<td class="value">
<%= link_to "#{(a)product.product_roles.size} Members",
- users_path(:product => @product) %>
+ product_roles_path(@product) %>
</td>
</tr>
diff --git a/app/views/roles/_list.html.erb b/app/views/roles/_list.html.erb
new file mode 100644
index 0000000..8692122
--- /dev/null
+++ b/app/views/roles/_list.html.erb
@@ -0,0 +1,85 @@
+<% columns = 4 - (@this_user ? 1 : 0) + (@product ? 0 : 1) + (@product &&
@product.can_approve_roles?(@user) ? 1 : 0) %>
+
+<% if @product %>
+ <%= link_to @product.name, product_path(@product) %>
+<% end %>
+
+<table class="list">
+ <colgroup>
+ <col class="row_id" />
+ <% unless @this_user %>
+ <col class="user" />
+ <% end %>
+ <% unless @product %>
+ <col class="name" />
+ <% end %>
+ <col class="description" />
+ <col class="date" />
+
+ <% if @product && @product.can_approve_roles?(@user) %>
+ <col class="actions" />
+ <% end %>
+ </colgroup>
+
+ <thead>
+ <tr>
+ <th class="title" colspan="<%= columns %>">
+ Product Roles
+ </th>
+ </tr>
+ <tr>
+ <th>#</th>
+
+ <% unless @this_user %>
+ <th>User</th>
+ <% end %>
+
+ <% unless @product %>
+ <th>Product</th>
+ <% end %>
+
+ <th>Role</th>
+ <th>Since</th>
+ <% if @product && @product.can_approve_roles?(@user) %>
+ <th>Actions</th>
+ <% end %>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @product_roles.each_with_index do |role, index| %>
+ <% row_class = index%2 == 0 ? 'even' : 'odd' %>
+ <tr class="<%= row_class %>">
+ <td><%= link_to "#{role.id}", product_role_path(role.product,
role) %>
+
+ <% unless @this_user %>
+ <td><%= link_to role.user.display_name,roles_user_path(role.user)
%></td>
+ <% end %>
+
+ <% unless @product %>
+ <td><%= link_to role.product.name, product_roles_path(role.product)
%>
+ <% end %>
+
+ <td><%= role.role.name %></td>
+ <td><%= show_date role.created_at %></td>
+ <% if @product && @product.can_approve_roles?(@user) %>
+ <td>
+ <% if role.pending %>
+ <% form_for(:product_role, role, :url =>
product_role_path(role.product,role),
+ :html => {:method => :put}) do |form| %>
+ <%= form.radio_button :approved, true %>Approve
+ <%= form.radio_button :approved, false %>Deny
+ <%= submit_tag "Update" %>
+ <% end %>
+ <% else %>
+ <% form_for(:product_role, role, :url =>
product_role_path(role.product,role),
+ :html => {:method => :delete}) do |form| %>
+ <%= submit_tag "Delete", :confirm => "Are you
sure?" %>
+ <% end %>
+ <% end %>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
diff --git a/app/views/roles/index.html.erb b/app/views/roles/index.html.erb
index c96bd6f..c32fe36 100644
--- a/app/views/roles/index.html.erb
+++ b/app/views/roles/index.html.erb
@@ -1,42 +1,2 @@
-<%= link_to @product.name, product_path(@product) %>
-
-<table class="list">
- <thead>
- <tr>
- <th>User</th>
- <th>Role</th>
- <th>Created</th>
- <% if @product.can_approve_roles?(@user) %>
- <th>Actions</th>
- <% end %>
- </tr>
- </thead>
-
- <tbody>
- <% @product_roles.each_with_index do |role, index| %>
- <% row_class = index%2 == 0 ? 'even' : 'odd' %>
- <tr class="<%= row_class %>">
- <td><%= link_to role.user.display_name,user_path(role.user)
%></td>
- <td><%= role.role.name %></td>
- <td><%= role.created_at %></td>
- <% if @product.can_approve_roles?(@user) %>
- <td>
- <% if role.pending %>
- <% form_for(:product_role, role, :url =>
product_role_path(role.product,role),
- :html => {:method => :put}) do |form| %>
- <%= form.radio_button :approved, true %>Approve
- <%= form.radio_button :approved, false %>Deny
- <%= submit_tag "Update" %>
- <% end %>
- <% else %>
- <% form_for(:product_role, role, :url =>
product_role_path(role.product,role),
- :html => {:method => :delete}) do |form| %>
- <%= submit_tag "Delete", :confirm => "Are you
sure?" %>
- <% end %>
- <% end %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
-</table>
+<%= will_paginate @product_roles %>
+<%= render :partial => 'list' %>
diff --git a/app/views/users/_list.html.erb b/app/views/users/_list.html.erb
index 9fc055e..e3101e1 100644
--- a/app/views/users/_list.html.erb
+++ b/app/views/users/_list.html.erb
@@ -33,7 +33,7 @@
<td><%= simple_format user.introduction %></td>
<td><%= link_to user.email, "mailto:#{user.email}"
%></td>
<td><%= link_to "#{user.backlog.size} items",
backlog_user_path(user) %>
- <td><%= "#{user.product_roles.size} roles" %></td>
+ <td><%= link_to "#{user.product_roles.size} roles",
roles_user_path(user) %></td>
<td><%= show_date(user.created_at) %></td>
<td>
<%= link_to(image_tag("icons/view.png", :alt => "View
user..."), user_path(user)) %>
diff --git a/app/views/users/roles.html.erb b/app/views/users/roles.html.erb
new file mode 100644
index 0000000..78cf239
--- /dev/null
+++ b/app/views/users/roles.html.erb
@@ -0,0 +1,2 @@
+<%= will_paginate @product_roles %>
+<%= render :partial => 'roles/list' %>
diff --git a/config/routes.rb b/config/routes.rb
index bb87d4c..d4d2ec6 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -20,7 +20,7 @@ ActionController::Routing::Routes.draw do |map|
map.resources :products do |product|
product.resources :roles
product.resources :stories
- product.resources(:sprints, :member => {:plan => :get, :populate => :post})
do |sprint|
+ product.resources(:sprints, :member => {:plan => :get, :populate => :post,
:roles => :get}) do |sprint|
sprint.resources :items, :member =>
{
:accept => :get,
@@ -30,7 +30,7 @@ ActionController::Routing::Routes.draw do |map|
}
end
end
- map.resources :users, :member => {:backlog => :get} do |user|
+ map.resources :users, :member => {:backlog => :get, :roles => :get} do |user|
user.resources :tasks
end
diff --git a/test/functional/users_controller_test.rb
b/test/functional/users_controller_test.rb
index 170541e..7375369 100644
--- a/test/functional/users_controller_test.rb
+++ b/test/functional/users_controller_test.rb
@@ -294,4 +294,19 @@ class UsersControllerTest < ActionController::TestCase
assert User.find_by_id((a)unverified_user.id).verified?,
"User should be verified."
end
+
+ # Ensures that viewing roles requires a valid user id.
+ def test_roles_with_invalid_user_id
+ get :roles
+
+ assert_redirected_to users_path
+ end
+
+ # Ensures that the set of roles are loaded.
+ def test_roles
+ get :roles, {:id => @user.id}
+
+ assert_response :success
+ assert assigns['product_roles'], "Failed to load the user's
roles."
+ end
end
--
1.5.6.5