comparison app/controllers/users_controller.rb @ 60:cf39b52d24b4 luisf

DEVELOPMENT COMMIT: The description can now be seen and edited BUT when a new user registers the informations is not saved to the correct table.
author luisf
date Wed, 01 Dec 2010 18:04:19 +0000
parents e77d73b181e3
children aedfe093ec32
comparison
equal deleted inserted replaced
59:7ff14a13f48a 60:cf39b52d24b4
51 51
52 def show 52 def show
53 @user = User.find(params[:id]) 53 @user = User.find(params[:id])
54 54
55 @description = @user.ssamr_user_detail.description 55 @description = @user.ssamr_user_detail.description
56 56
57 # @description = @user.ssamr_user_detail.description
58
59 # show projects based on current user visibility 57 # show projects based on current user visibility
60 @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current)) 58 @memberships = @user.memberships.all(:conditions => Project.visible_by(User.current))
61 59
62 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) 60 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
63 @events_by_day = events.group_by(&:event_date) 61 @events_by_day = events.group_by(&:event_date)
72 70
73 rescue ActiveRecord::RecordNotFound 71 rescue ActiveRecord::RecordNotFound
74 render_404 72 render_404
75 end 73 end
76 74
77 def new 75 def new
78 @notification_options = User::MAIL_NOTIFICATION_OPTIONS 76 @notification_options = User::MAIL_NOTIFICATION_OPTIONS
79 @notification_option = Setting.default_notification_option 77 @notification_option = Setting.default_notification_option
80 78
81 @user = User.new(:language => Setting.default_language) 79 @user = User.new(:language => Setting.default_language)
82 @auth_sources = AuthSource.find(:all) 80 @auth_sources = AuthSource.find(:all)
81
82 @ssamr_user_details = SsamrUserDetail.new
83
83 end 84 end
84 85
85 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } 86 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
86 def create 87 def create
87 @notification_options = User::MAIL_NOTIFICATION_OPTIONS 88 @notification_options = User::MAIL_NOTIFICATION_OPTIONS
88 @notification_option = Setting.default_notification_option 89 @notification_option = Setting.default_notification_option
89 90
90 @user = User.new(params[:user]) 91 @user = User.new(params[:user])
91 @user.admin = params[:user][:admin] || false 92 @user.admin = params[:user][:admin] || false
92 @user.login = params[:user][:login] 93 @user.login = params[:user][:login]
93 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id 94 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
94
95 @user.ssamr_user_detail.description = params[:user.ssamr_user_detail][:description]
96
97 @ssamr_description = params[:user.ssamr_user_detail][:description]
98 95
99 # TODO: Similar to My#account 96 # TODO: Similar to My#account
100 @user.mail_notification = params[:notification_option] || 'only_my_events' 97 @user.mail_notification = params[:notification_option] || 'only_my_events'
101 @user.pref.attributes = params[:pref] 98 @user.pref.attributes = params[:pref]
102 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') 99 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
103 100
101 @ssamr_user_details = @user.ssamr_user_detail
102 @ssamr_user_details.description = params[:ssamr_user_details][:description]
103
104 if @user.save 104 if @user.save
105 @user.pref.save 105 @user.pref.save
106
107 @ssamr_user_details.save!
108
106 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) 109 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
107 110
108 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] 111 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
109 flash[:notice] = l(:notice_successful_create) 112 flash[:notice] = l(:notice_successful_create)
110 redirect_to(params[:continue] ? {:controller => 'users', :action => 'new'} : 113 redirect_to(params[:continue] ? {:controller => 'users', :action => 'new'} :
121 def edit 124 def edit
122 @user = User.find(params[:id]) 125 @user = User.find(params[:id])
123 @notification_options = @user.valid_notification_options 126 @notification_options = @user.valid_notification_options
124 @notification_option = @user.mail_notification 127 @notification_option = @user.mail_notification
125 128
126 # @ssamr_description = @user.ssamr_user_detail 129 @ssamr_user_details = @user.ssamr_user_detail
127 130
128 @auth_sources = AuthSource.find(:all) 131 @auth_sources = AuthSource.find(:all)
129 @membership ||= Member.new 132 @membership ||= Member.new
130 end 133 end
131 134
132 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } 135 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
133 def update 136 def update
134 @user = User.find(params[:id]) 137 @user = User.find(params[:id])
135 138
136 @notification_options = @user.valid_notification_options 139 @notification_options = @user.valid_notification_options
137 @notification_option = @user.mail_notification 140 @notification_option = @user.mail_notification
138 141
139 @user.admin = params[:user][:admin] if params[:user][:admin] 142 @user.admin = params[:user][:admin] if params[:user][:admin]
140 @user.login = params[:user][:login] if params[:user][:login] 143 @user.login = params[:user][:login] if params[:user][:login]
148 # TODO: Similar to My#account 151 # TODO: Similar to My#account
149 @user.mail_notification = params[:notification_option] || 'only_my_events' 152 @user.mail_notification = params[:notification_option] || 'only_my_events'
150 @user.pref.attributes = params[:pref] 153 @user.pref.attributes = params[:pref]
151 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') 154 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
152 155
156 @ssamr_user_details = @user.ssamr_user_detail
157 @ssamr_user_details.description = params[:ssamr_user_details][:description]
158
159 @ssamr_user_details.save!
160
161
153 if @user.save 162 if @user.save
154 @user.pref.save 163 @user.pref.save
155 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) 164 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
156 165
157 if was_activated 166 if was_activatedd
158 Mailer.deliver_account_activated(@user) 167 Mailer.deliver_account_activated(@user)
159 elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? 168 elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil?
160 Mailer.deliver_account_information(@user, params[:password]) 169 Mailer.deliver_account_information(@user, params[:password])
161 end 170 end
162 flash[:notice] = l(:notice_successful_update) 171 flash[:notice] = l(:notice_successful_update)