Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a way to add and remove users from iterations - yeah I did that.

  • Loading branch information...
commit d67a82b45a42ef2c9b26d686c1725c59de8a06db 1 parent b66b6c3
Steve authored
View
13 app/controllers/users_controller.rb
@@ -20,6 +20,7 @@ class UsersController < ApplicationController
before_filter :find_user, :only => [:suspend, :destroy, :activate]
before_filter :must_be_admin, :only => [:new, :create, :destroy, :suspend, :activate]
before_filter :must_be_admin_or_self, :only => [:edit, :update]
+ before_filter :add_participations, :only => [:create, :update]
def index
@users = User.find(:all)
@@ -96,5 +97,15 @@ def must_be_admin
end
end
-end
+ def add_participations
+ unless params[:user][:participations].nil?
+ # blow em away
+ Participation.find(:all,
+ :conditions => ["user_id = ?", params[:id]]).each { |p| p.destroy }
+ params[:user].delete(:participations).each do |participation|
+ Participation.create(:user_id => params[:id], :iteration_id => participation[:iteration])
+ end
+ end
+ end
+end
View
8 app/helpers/users_helper.rb
@@ -1,5 +1,5 @@
module UsersHelper
-
+
#
# Use this to wrap view elements that the user can't access.
# !! Note: this is an *interface*, not *security* feature !!
@@ -8,7 +8,7 @@ module UsersHelper
# Example:
# <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> |
# <%= if_authorized?(:edit, @user) do link_to('Edit this user', edit_user_path) end %> |
- # <%= if_authorized?(:destroy, @user) do link_to 'Destroy', @user, :confirm => 'Are you sure?', :method => :delete end %>
+ # <%= if_authorized?(:destroy, @user) do link_to 'Destroy', @user, :confirm => 'Are you sure?', :method => :delete end %>
#
#
def if_authorized?(action, resource, &block)
@@ -55,7 +55,7 @@ def link_to_user(user, options={})
#
# Link to login page using remote ip address as link content
#
- # The :title (and thus, tooltip) is set to the IP address
+ # The :title (and thus, tooltip) is set to the IP address
#
# Examples:
# link_to_login_with_IP
@@ -85,7 +85,7 @@ def link_to_current_user(options={})
else
content_text = options.delete(:content_text) || 'not signed in'
# kill ignored options from link_to_user
- [:content_method, :title_method].each{|opt| options.delete(opt)}
+ [:content_method, :title_method].each{|opt| options.delete(opt)}
link_to_login_with_IP content_text, options
end
end
View
14 app/models/user.rb
@@ -44,7 +44,7 @@ class User < ActiveRecord::Base
# HACK HACK HACK -- how to do attr_accessible from here?
# prevents a user from submitting a crafted form that bypasses activation
# anything else you want your user to change should be added here.
- attr_accessible :login, :email, :name, :password, :password_confirmation
+ attr_accessible :login, :email, :name, :password, :password_confirmation, :participations
include AASM
aasm_column :state
@@ -99,6 +99,17 @@ def to_s
login
end
+ def participant?(iteration)
+ is_participant = false
+ participations.each do |participation|
+ if iteration.to_param == participation.iteration.to_param
+ is_participant = true
+ break
+ end
+ end
+ is_participant
+ end
+
protected
# Returns true if the user has just been activated.
@@ -117,4 +128,3 @@ def do_activate
end
end
-
View
21 app/views/users/_form.html.erb
@@ -1,27 +1,36 @@
<p class="form-fields">
- <%= label_tag 'login' %>
+ <%= label_tag 'Login' %>
<%= f.text_field :login %>
</p>
<p class="form-fields">
- <%= label_tag 'email' %>
+ <%= label_tag 'Email' %>
<%= f.text_field :email %>
</p>
<p class="form-fields">
- <%= label_tag 'password' %>
+ <%= label_tag 'Password' %>
<%= f.password_field :password %>
</p>
<p class="form-fields">
- <%= label_tag 'password_confirmation', 'Confirm Password' %>
+ <%= label_tag 'password_confirmation', 'Confirm' %>
<%= f.password_field :password_confirmation %>
</p>
<% if current_user.has_role?("admin") -%>
+ <hr/>
<p class="form-fields">
- <%= label_tag 'role' %>
+ <%= label_tag 'Role' %>
<%= f.select :role, ["admin", "client", "developer"] %>
</p>
+ <p class="form-fields">
+ <%= label_tag 'Project Access' %>
+ <div>
+ <% Iteration.all.each_with_index do |iteration, index| -%>
+ <%= check_box_tag "user[participations][][iteration]", iteration.to_param, @user.participant?(iteration) %>
+ &nbsp;<%= iteration.name %>&nbsp;(<%= iteration.project.name %>)<br/>
+ <% end -%>
+ </div>
+ </p>
<% end -%>
-
View
6 test/unit/helpers/iterations_helper_test.rb
@@ -30,13 +30,13 @@ class IterationsHelperTest < ActionView::TestCase
assert_equal "string", burndown_json["cols"][0]["type"]
assert_equal "number", burndown_json["cols"][1]["type"]
assert_equal "number", burndown_json["cols"][2]["type"]
- assert_equal "24-05-2011", burndown_json["rows"][0]["c"][0]["v"]
+ assert_equal @weekdays[0].strftime('%d-%m-%Y'), burndown_json["rows"][0]["c"][0]["v"]
assert_equal 13, burndown_json["rows"][0]["c"][1]["v"]
assert_equal "0 points. 13 remaining.", burndown_json["rows"][0]["c"][1]["f"]
- assert_equal "26-05-2011", burndown_json["rows"][2]["c"][0]["v"]
+ assert_equal @weekdays[2].strftime('%d-%m-%Y'), burndown_json["rows"][2]["c"][0]["v"]
assert_equal 4, burndown_json["rows"][2]["c"][1]["v"]
assert_equal "9 points. 4 remaining.", burndown_json["rows"][2]["c"][1]["f"]
- assert_equal "27-05-2011", burndown_json["rows"][3]["c"][0]["v"]
+ assert_equal @weekdays[3].strftime('%d-%m-%Y'), burndown_json["rows"][3]["c"][0]["v"]
assert_equal 1, burndown_json["rows"][3]["c"][1]["v"]
assert_equal "12 points. 1 remaining.", burndown_json["rows"][3]["c"][1]["f"]
end
Please sign in to comment.
Something went wrong with that request. Please try again.