@@ -1,163 +1,162 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class GroupsController < ApplicationController |
|
18 | class GroupsController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin |
|
21 | before_filter :require_admin | |
22 |
|
22 | |||
23 | helper :custom_fields |
|
23 | helper :custom_fields | |
24 |
|
24 | |||
25 | # GET /groups |
|
25 | # GET /groups | |
26 | # GET /groups.xml |
|
26 | # GET /groups.xml | |
27 | def index |
|
27 | def index | |
28 | @groups = Group.find(:all, :order => 'lastname') |
|
28 | @groups = Group.find(:all, :order => 'lastname') | |
29 |
|
29 | |||
30 | respond_to do |format| |
|
30 | respond_to do |format| | |
31 | format.html # index.html.erb |
|
31 | format.html # index.html.erb | |
32 | format.xml { render :xml => @groups } |
|
32 | format.xml { render :xml => @groups } | |
33 | end |
|
33 | end | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | # GET /groups/1 |
|
36 | # GET /groups/1 | |
37 | # GET /groups/1.xml |
|
37 | # GET /groups/1.xml | |
38 | def show |
|
38 | def show | |
39 | @group = Group.find(params[:id]) |
|
39 | @group = Group.find(params[:id]) | |
40 |
|
40 | |||
41 | respond_to do |format| |
|
41 | respond_to do |format| | |
42 | format.html # show.html.erb |
|
42 | format.html # show.html.erb | |
43 | format.xml { render :xml => @group } |
|
43 | format.xml { render :xml => @group } | |
44 | end |
|
44 | end | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | # GET /groups/new |
|
47 | # GET /groups/new | |
48 | # GET /groups/new.xml |
|
48 | # GET /groups/new.xml | |
49 | def new |
|
49 | def new | |
50 | @group = Group.new |
|
50 | @group = Group.new | |
51 |
|
51 | |||
52 | respond_to do |format| |
|
52 | respond_to do |format| | |
53 | format.html # new.html.erb |
|
53 | format.html # new.html.erb | |
54 | format.xml { render :xml => @group } |
|
54 | format.xml { render :xml => @group } | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | # GET /groups/1/edit |
|
58 | # GET /groups/1/edit | |
59 | def edit |
|
59 | def edit | |
60 | @group = Group.find(params[:id]) |
|
60 | @group = Group.find(params[:id]) | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | # POST /groups |
|
63 | # POST /groups | |
64 | # POST /groups.xml |
|
64 | # POST /groups.xml | |
65 | def create |
|
65 | def create | |
66 | @group = Group.new(params[:group]) |
|
66 | @group = Group.new(params[:group]) | |
67 |
|
67 | |||
68 | respond_to do |format| |
|
68 | respond_to do |format| | |
69 | if @group.save |
|
69 | if @group.save | |
70 | flash[:notice] = l(:notice_successful_create) |
|
70 | flash[:notice] = l(:notice_successful_create) | |
71 | format.html { redirect_to(groups_path) } |
|
71 | format.html { redirect_to(groups_path) } | |
72 | format.xml { render :xml => @group, :status => :created, :location => @group } |
|
72 | format.xml { render :xml => @group, :status => :created, :location => @group } | |
73 | else |
|
73 | else | |
74 | format.html { render :action => "new" } |
|
74 | format.html { render :action => "new" } | |
75 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } |
|
75 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } | |
76 | end |
|
76 | end | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | # PUT /groups/1 |
|
80 | # PUT /groups/1 | |
81 | # PUT /groups/1.xml |
|
81 | # PUT /groups/1.xml | |
82 | def update |
|
82 | def update | |
83 | @group = Group.find(params[:id]) |
|
83 | @group = Group.find(params[:id]) | |
84 |
|
84 | |||
85 | respond_to do |format| |
|
85 | respond_to do |format| | |
86 | if @group.update_attributes(params[:group]) |
|
86 | if @group.update_attributes(params[:group]) | |
87 | flash[:notice] = l(:notice_successful_update) |
|
87 | flash[:notice] = l(:notice_successful_update) | |
88 | format.html { redirect_to(groups_path) } |
|
88 | format.html { redirect_to(groups_path) } | |
89 | format.xml { head :ok } |
|
89 | format.xml { head :ok } | |
90 | else |
|
90 | else | |
91 | format.html { render :action => "edit" } |
|
91 | format.html { render :action => "edit" } | |
92 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } |
|
92 | format.xml { render :xml => @group.errors, :status => :unprocessable_entity } | |
93 | end |
|
93 | end | |
94 | end |
|
94 | end | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | # DELETE /groups/1 |
|
97 | # DELETE /groups/1 | |
98 | # DELETE /groups/1.xml |
|
98 | # DELETE /groups/1.xml | |
99 | def destroy |
|
99 | def destroy | |
100 | @group = Group.find(params[:id]) |
|
100 | @group = Group.find(params[:id]) | |
101 | @group.destroy |
|
101 | @group.destroy | |
102 |
|
102 | |||
103 | respond_to do |format| |
|
103 | respond_to do |format| | |
104 | format.html { redirect_to(groups_url) } |
|
104 | format.html { redirect_to(groups_url) } | |
105 | format.xml { head :ok } |
|
105 | format.xml { head :ok } | |
106 | end |
|
106 | end | |
107 | end |
|
107 | end | |
108 |
|
108 | |||
109 | def add_users |
|
109 | def add_users | |
110 | @group = Group.find(params[:id]) |
|
110 | @group = Group.find(params[:id]) | |
111 | users = User.find_all_by_id(params[:user_ids]) |
|
111 | users = User.find_all_by_id(params[:user_ids]) | |
112 | @group.users << users if request.post? |
|
112 | @group.users << users if request.post? | |
113 | respond_to do |format| |
|
113 | respond_to do |format| | |
114 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
114 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } | |
115 | format.js { |
|
115 | format.js { | |
116 | render(:update) {|page| |
|
116 | render(:update) {|page| | |
117 | page.replace_html "tab-content-users", :partial => 'groups/users' |
|
117 | page.replace_html "tab-content-users", :partial => 'groups/users' | |
118 | users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } |
|
118 | users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } | |
119 | } |
|
119 | } | |
120 | } |
|
120 | } | |
121 | end |
|
121 | end | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | def remove_user |
|
124 | def remove_user | |
125 | @group = Group.find(params[:id]) |
|
125 | @group = Group.find(params[:id]) | |
126 | @group.users.delete(User.find(params[:user_id])) if request.post? |
|
126 | @group.users.delete(User.find(params[:user_id])) if request.post? | |
127 | respond_to do |format| |
|
127 | respond_to do |format| | |
128 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
128 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } | |
129 | format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } |
|
129 | format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } | |
130 | end |
|
130 | end | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def autocomplete_for_user |
|
133 | def autocomplete_for_user | |
134 | @group = Group.find(params[:id]) |
|
134 | @group = Group.find(params[:id]) | |
135 | @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users |
|
135 | @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users | |
136 | render :layout => false |
|
136 | render :layout => false | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | def edit_membership |
|
139 | def edit_membership | |
140 | @group = Group.find(params[:id]) |
|
140 | @group = Group.find(params[:id]) | |
141 |
@membership = |
|
141 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) | |
142 | @membership.attributes = params[:membership] |
|
|||
143 | @membership.save if request.post? |
|
142 | @membership.save if request.post? | |
144 | respond_to do |format| |
|
143 | respond_to do |format| | |
145 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
144 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } | |
146 | format.js { |
|
145 | format.js { | |
147 | render(:update) {|page| |
|
146 | render(:update) {|page| | |
148 | page.replace_html "tab-content-memberships", :partial => 'groups/memberships' |
|
147 | page.replace_html "tab-content-memberships", :partial => 'groups/memberships' | |
149 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
148 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
150 | } |
|
149 | } | |
151 | } |
|
150 | } | |
152 | end |
|
151 | end | |
153 | end |
|
152 | end | |
154 |
|
153 | |||
155 | def destroy_membership |
|
154 | def destroy_membership | |
156 | @group = Group.find(params[:id]) |
|
155 | @group = Group.find(params[:id]) | |
157 | Member.find(params[:membership_id]).destroy if request.post? |
|
156 | Member.find(params[:membership_id]).destroy if request.post? | |
158 | respond_to do |format| |
|
157 | respond_to do |format| | |
159 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
158 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } | |
160 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } |
|
159 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } | |
161 | end |
|
160 | end | |
162 | end |
|
161 | end | |
163 | end |
|
162 | end |
@@ -1,148 +1,147 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class UsersController < ApplicationController |
|
18 | class UsersController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :except => :show |
|
21 | before_filter :require_admin, :except => :show | |
22 |
|
22 | |||
23 | helper :sort |
|
23 | helper :sort | |
24 | include SortHelper |
|
24 | include SortHelper | |
25 | helper :custom_fields |
|
25 | helper :custom_fields | |
26 | include CustomFieldsHelper |
|
26 | include CustomFieldsHelper | |
27 |
|
27 | |||
28 | def index |
|
28 | def index | |
29 | sort_init 'login', 'asc' |
|
29 | sort_init 'login', 'asc' | |
30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
31 |
|
31 | |||
32 | @status = params[:status] ? params[:status].to_i : 1 |
|
32 | @status = params[:status] ? params[:status].to_i : 1 | |
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
34 |
|
34 | |||
35 | unless params[:name].blank? |
|
35 | unless params[:name].blank? | |
36 | name = "%#{params[:name].strip.downcase}%" |
|
36 | name = "%#{params[:name].strip.downcase}%" | |
37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | @user_count = User.count(:conditions => c.conditions) |
|
40 | @user_count = User.count(:conditions => c.conditions) | |
41 | @user_pages = Paginator.new self, @user_count, |
|
41 | @user_pages = Paginator.new self, @user_count, | |
42 | per_page_option, |
|
42 | per_page_option, | |
43 | params['page'] |
|
43 | params['page'] | |
44 | @users = User.find :all,:order => sort_clause, |
|
44 | @users = User.find :all,:order => sort_clause, | |
45 | :conditions => c.conditions, |
|
45 | :conditions => c.conditions, | |
46 | :limit => @user_pages.items_per_page, |
|
46 | :limit => @user_pages.items_per_page, | |
47 | :offset => @user_pages.current.offset |
|
47 | :offset => @user_pages.current.offset | |
48 |
|
48 | |||
49 | render :layout => !request.xhr? |
|
49 | render :layout => !request.xhr? | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def show |
|
52 | def show | |
53 | @user = User.find(params[:id]) |
|
53 | @user = User.find(params[:id]) | |
54 | @custom_values = @user.custom_values |
|
54 | @custom_values = @user.custom_values | |
55 |
|
55 | |||
56 | # show only public projects and private projects that the logged in user is also a member of |
|
56 | # show only public projects and private projects that the logged in user is also a member of | |
57 | @memberships = @user.memberships.select do |membership| |
|
57 | @memberships = @user.memberships.select do |membership| | |
58 | membership.project.is_public? || (User.current.member_of?(membership.project)) |
|
58 | membership.project.is_public? || (User.current.member_of?(membership.project)) | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) | |
62 | @events_by_day = events.group_by(&:event_date) |
|
62 | @events_by_day = events.group_by(&:event_date) | |
63 |
|
63 | |||
64 | unless User.current.admin? |
|
64 | unless User.current.admin? | |
65 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) |
|
65 | if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) | |
66 | render_404 |
|
66 | render_404 | |
67 | return |
|
67 | return | |
68 | end |
|
68 | end | |
69 | end |
|
69 | end | |
70 | render :layout => 'base' |
|
70 | render :layout => 'base' | |
71 |
|
71 | |||
72 | rescue ActiveRecord::RecordNotFound |
|
72 | rescue ActiveRecord::RecordNotFound | |
73 | render_404 |
|
73 | render_404 | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def add |
|
76 | def add | |
77 | if request.get? |
|
77 | if request.get? | |
78 | @user = User.new(:language => Setting.default_language) |
|
78 | @user = User.new(:language => Setting.default_language) | |
79 | else |
|
79 | else | |
80 | @user = User.new(params[:user]) |
|
80 | @user = User.new(params[:user]) | |
81 | @user.admin = params[:user][:admin] || false |
|
81 | @user.admin = params[:user][:admin] || false | |
82 | @user.login = params[:user][:login] |
|
82 | @user.login = params[:user][:login] | |
83 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id |
|
83 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id | |
84 | if @user.save |
|
84 | if @user.save | |
85 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
85 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] | |
86 | flash[:notice] = l(:notice_successful_create) |
|
86 | flash[:notice] = l(:notice_successful_create) | |
87 | redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : |
|
87 | redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : | |
88 | {:controller => 'users', :action => 'edit', :id => @user}) |
|
88 | {:controller => 'users', :action => 'edit', :id => @user}) | |
89 | return |
|
89 | return | |
90 | end |
|
90 | end | |
91 | end |
|
91 | end | |
92 | @auth_sources = AuthSource.find(:all) |
|
92 | @auth_sources = AuthSource.find(:all) | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def edit |
|
95 | def edit | |
96 | @user = User.find(params[:id]) |
|
96 | @user = User.find(params[:id]) | |
97 | if request.post? |
|
97 | if request.post? | |
98 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
98 | @user.admin = params[:user][:admin] if params[:user][:admin] | |
99 | @user.login = params[:user][:login] if params[:user][:login] |
|
99 | @user.login = params[:user][:login] if params[:user][:login] | |
100 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id |
|
100 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id | |
101 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] |
|
101 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] | |
102 | @user.attributes = params[:user] |
|
102 | @user.attributes = params[:user] | |
103 | # Was the account actived ? (do it before User#save clears the change) |
|
103 | # Was the account actived ? (do it before User#save clears the change) | |
104 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
104 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) | |
105 | if @user.save |
|
105 | if @user.save | |
106 | if was_activated |
|
106 | if was_activated | |
107 | Mailer.deliver_account_activated(@user) |
|
107 | Mailer.deliver_account_activated(@user) | |
108 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? |
|
108 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? | |
109 | Mailer.deliver_account_information(@user, params[:password]) |
|
109 | Mailer.deliver_account_information(@user, params[:password]) | |
110 | end |
|
110 | end | |
111 | flash[:notice] = l(:notice_successful_update) |
|
111 | flash[:notice] = l(:notice_successful_update) | |
112 | redirect_to :back |
|
112 | redirect_to :back | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 | @auth_sources = AuthSource.find(:all) |
|
115 | @auth_sources = AuthSource.find(:all) | |
116 | @membership ||= Member.new |
|
116 | @membership ||= Member.new | |
117 | rescue ::ActionController::RedirectBackError |
|
117 | rescue ::ActionController::RedirectBackError | |
118 | redirect_to :controller => 'users', :action => 'edit', :id => @user |
|
118 | redirect_to :controller => 'users', :action => 'edit', :id => @user | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def edit_membership |
|
121 | def edit_membership | |
122 | @user = User.find(params[:id]) |
|
122 | @user = User.find(params[:id]) | |
123 |
@membership = |
|
123 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) | |
124 | @membership.attributes = params[:membership] |
|
|||
125 | @membership.save if request.post? |
|
124 | @membership.save if request.post? | |
126 | respond_to do |format| |
|
125 | respond_to do |format| | |
127 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
126 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
128 | format.js { |
|
127 | format.js { | |
129 | render(:update) {|page| |
|
128 | render(:update) {|page| | |
130 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' |
|
129 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' | |
131 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
130 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
132 | } |
|
131 | } | |
133 | } |
|
132 | } | |
134 | end |
|
133 | end | |
135 | end |
|
134 | end | |
136 |
|
135 | |||
137 | def destroy_membership |
|
136 | def destroy_membership | |
138 | @user = User.find(params[:id]) |
|
137 | @user = User.find(params[:id]) | |
139 | @membership = Member.find(params[:membership_id]) |
|
138 | @membership = Member.find(params[:membership_id]) | |
140 | if request.post? && @membership.deletable? |
|
139 | if request.post? && @membership.deletable? | |
141 | @membership.destroy |
|
140 | @membership.destroy | |
142 | end |
|
141 | end | |
143 | respond_to do |format| |
|
142 | respond_to do |format| | |
144 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
143 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
145 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
144 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } | |
146 | end |
|
145 | end | |
147 | end |
|
146 | end | |
148 | end |
|
147 | end |
@@ -1,89 +1,96 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Member < ActiveRecord::Base |
|
18 | class Member < ActiveRecord::Base | |
19 | belongs_to :user |
|
19 | belongs_to :user | |
20 | belongs_to :principal, :foreign_key => 'user_id' |
|
20 | belongs_to :principal, :foreign_key => 'user_id' | |
21 | has_many :member_roles, :dependent => :destroy |
|
21 | has_many :member_roles, :dependent => :destroy | |
22 | has_many :roles, :through => :member_roles |
|
22 | has_many :roles, :through => :member_roles | |
23 | belongs_to :project |
|
23 | belongs_to :project | |
24 |
|
24 | |||
25 | validates_presence_of :principal, :project |
|
25 | validates_presence_of :principal, :project | |
26 | validates_uniqueness_of :user_id, :scope => :project_id |
|
26 | validates_uniqueness_of :user_id, :scope => :project_id | |
27 |
|
27 | |||
28 | after_destroy :unwatch_from_permission_change |
|
28 | after_destroy :unwatch_from_permission_change | |
29 |
|
29 | |||
30 | def name |
|
30 | def name | |
31 | self.user.name |
|
31 | self.user.name | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | alias :base_role_ids= :role_ids= |
|
34 | alias :base_role_ids= :role_ids= | |
35 | def role_ids=(arg) |
|
35 | def role_ids=(arg) | |
36 | ids = (arg || []).collect(&:to_i) - [0] |
|
36 | ids = (arg || []).collect(&:to_i) - [0] | |
37 | # Keep inherited roles |
|
37 | # Keep inherited roles | |
38 | ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) |
|
38 | ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id) | |
39 |
|
39 | |||
40 | new_role_ids = ids - role_ids |
|
40 | new_role_ids = ids - role_ids | |
41 | # Add new roles |
|
41 | # Add new roles | |
42 | new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) } |
|
42 | new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) } | |
43 | # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy) |
|
43 | # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy) | |
44 | member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)} |
|
44 | member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)} | |
45 | if member_roles_to_destroy.any? |
|
45 | if member_roles_to_destroy.any? | |
46 | member_roles_to_destroy.each(&:destroy) |
|
46 | member_roles_to_destroy.each(&:destroy) | |
47 | unwatch_from_permission_change |
|
47 | unwatch_from_permission_change | |
48 | end |
|
48 | end | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def <=>(member) |
|
51 | def <=>(member) | |
52 | a, b = roles.sort.first, member.roles.sort.first |
|
52 | a, b = roles.sort.first, member.roles.sort.first | |
53 | a == b ? (principal <=> member.principal) : (a <=> b) |
|
53 | a == b ? (principal <=> member.principal) : (a <=> b) | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def deletable? |
|
56 | def deletable? | |
57 | member_roles.detect {|mr| mr.inherited_from}.nil? |
|
57 | member_roles.detect {|mr| mr.inherited_from}.nil? | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def include?(user) |
|
60 | def include?(user) | |
61 | if principal.is_a?(Group) |
|
61 | if principal.is_a?(Group) | |
62 | !user.nil? && user.groups.include?(principal) |
|
62 | !user.nil? && user.groups.include?(principal) | |
63 | else |
|
63 | else | |
64 | self.user == user |
|
64 | self.user == user | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def before_destroy |
|
68 | def before_destroy | |
69 | if user |
|
69 | if user | |
70 | # remove category based auto assignments for this member |
|
70 | # remove category based auto assignments for this member | |
71 | IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id] |
|
71 | IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id] | |
72 | end |
|
72 | end | |
73 | end |
|
73 | end | |
|
74 | ||||
|
75 | # Find or initilize a Member with an id, attributes, and for a Principal | |||
|
76 | def self.edit_membership(id, new_attributes, principal=nil) | |||
|
77 | @membership = id.present? ? Member.find(id) : Member.new(:principal => principal) | |||
|
78 | @membership.attributes = new_attributes | |||
|
79 | @membership | |||
|
80 | end | |||
74 |
|
81 | |||
75 | protected |
|
82 | protected | |
76 |
|
83 | |||
77 | def validate |
|
84 | def validate | |
78 | errors.add_to_base "Role can't be blank" if member_roles.empty? && roles.empty? |
|
85 | errors.add_to_base "Role can't be blank" if member_roles.empty? && roles.empty? | |
79 | end |
|
86 | end | |
80 |
|
87 | |||
81 | private |
|
88 | private | |
82 |
|
89 | |||
83 | # Unwatch things that the user is no longer allowed to view inside project |
|
90 | # Unwatch things that the user is no longer allowed to view inside project | |
84 | def unwatch_from_permission_change |
|
91 | def unwatch_from_permission_change | |
85 | if user |
|
92 | if user | |
86 | Watcher.prune(:user => user, :project => project) |
|
93 | Watcher.prune(:user => user, :project => project) | |
87 | end |
|
94 | end | |
88 | end |
|
95 | end | |
89 | end |
|
96 | end |
General Comments 0
You need to be logged in to leave comments.
Login now