diff --git a/app/controllers/user_emails_controller.rb b/app/controllers/user_emails_controller.rb index 64ba07341..d85e930e5 100644 --- a/app/controllers/user_emails_controller.rb +++ b/app/controllers/user_emails_controller.rb @@ -1,21 +1,27 @@ # coding: UTF-8 -class UserEmailsController < ApplicationController - layout 'sessions' - before_filter :authenticate_user! +class UserEmailsController < UsersController + before_filter :find_user - def edit - (5 - current_user.emails.count).times {current_user.emails.build } - render 'users/emails/emails' + def index + @emails = @user.emails + (5 - @user.emails.count).times {|e| @emails << UserEmail.new(:user_id => @user) } end def update - new_emails = [] - params[:user][:emails_attributes].each_value {|x| new_emails << x[:email] if x[:email].present?} - emails = current_user.emails - emails.each {|e| e.destroy unless new_emails.include?(e.email)} - new_emails.each {|e| emails.create(:email => e) unless emails.include? e} - - flash[:notice] = t('flash.user.emails.saved') - redirect_to edit_user_emails_path + @user.role = params[:user][:role] + if @user.update_attributes(params[:user]) + flash[:notice] = t('flash.user.saved') + redirect_to users_path + else + flash[:error] = t('flash.user.save_error') + render :action => :edit + end end + + def destroy + @user.destroy + flash[:notice] = t("flash.user.destroyed") + redirect_to users_path + end + end diff --git a/app/models/comment.rb b/app/models/comment.rb index 683b7c742..13118e964 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -28,7 +28,7 @@ class Comment < ActiveRecord::Base self.commentable.subscribes.create(:user => self.user) if !self.commentable.subscribes.exists?(:user_id => self.user.id) elsif self.commentable.class == Grit::Commit recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map &:object # admins - recipients << self.user << UserEmail.where(:email => self.commentable.committer.email).first.try(:user) # commentor and committer + recipients << self.user << User.where(:email => self.commentable.committer.email).first # commentor and committer recipients << self.project.owner if self.project.owner_type == 'User' # project owner recipients.compact.uniq.each do |user| options = {:project_id => self.project.id, :subscribeable_id => self.commentable.id, :subscribeable_type => self.commentable.class.name, :user_id => user.id} diff --git a/app/models/user.rb b/app/models/user.rb index d6e9886a1..7494b06a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,10 +40,7 @@ class User < ActiveRecord::Base attr_readonly :uname attr_accessor :login - accepts_nested_attributes_for :emails, :allow_destroy => true - after_create :create_settings_notifier - after_create :add_user_email def admin? role == 'admin' @@ -61,7 +58,7 @@ class User < ActiveRecord::Base conditions = warden_conditions.dup login = conditions.delete(:login) where(conditions).where("lower(uname) = :value OR " + - "exists (select null from user_emails m where m.user_id = m.user_id and lower(m.email) = :value)", + "exists (select null from user_emails m where users.user_id = m.user_id and lower(m.email) = :value)", {:value => login.downcase}).first end @@ -106,7 +103,4 @@ class User < ActiveRecord::Base self.create_notifier end - def add_user_email - UserEmail.create(:user_id => self.id, :email => self.email) - end end diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 090c2c1e2..2202a2a97 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -78,4 +78,4 @@ = link_to t('layout.settings.notifier'), user_settings_notifier_path(current_user)#, :class => "text_button_padding link_button" .group.navform.wat-cf - = link_to t('layout.settings.emails'), edit_user_emails_path(current_user.id)#, :class => "text_button_padding link_button" + = link_to t('layout.settings.emails'), user_emails_path(current_user)#, :class => "text_button_padding link_button" diff --git a/app/views/users/emails.html.haml b/app/views/users/emails.html.haml new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/users/emails/_form.html.haml b/app/views/users/emails/_form.html.haml deleted file mode 100644 index 3fdb58400..000000000 --- a/app/views/users/emails/_form.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -= f.fields_for :emails do |m| - .group - .left - = m.text_field :email, :class => :text_field - .right - -.group.navform.wat-cf - %button.button{:type => "submit"} - = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save")) - = t("layout.save") - %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), edit_user_emails_path(current_user.id), :class => "text_button_padding link_button" -.group.navform.wat-cf - %span.text_button_padding - = link_to t('layout.back'), edit_user_registration_path, :class => "text_button_padding link_button" diff --git a/app/views/users/emails/emails.html.haml b/app/views/users/emails/emails.html.haml deleted file mode 100644 index 096e1055d..000000000 --- a/app/views/users/emails/emails.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -#block-signup.block - %h2= title t("layout.settings.email.list") - .content - = form_for current_user, :url => update_user_emails_path(@user), :html => {:method => :put, :id => current_user.id } do |f| - = render :partial => "users/emails/form", :locals => {:f => f} diff --git a/config/locales/en.yml b/config/locales/en.yml index 5cebbccc9..f8ae03bcf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,10 +45,7 @@ en: notifier: Notifier setting notifiers: edit_header: Notifier setting - email: - list: Email addresses - delete: Destroy - confirm_delete: Are you sure? + email: Email addresses processing: working ... downloads: @@ -433,9 +430,7 @@ en: saved: User saved save_error: User data saves error destroyed: User account deleted - emails: - saved: User emails saved - error: That emails addresses is already in use + group: saved: Group saved save_error: Group saves error diff --git a/config/locales/ru.yml b/config/locales/ru.yml index a558ceb75..80aed8c2b 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -44,10 +44,7 @@ ru: notifier: Настройки оповещений notifiers: edit_header: Настройки оповещений - email: - list: Список Email - delete: Удалить - confirm_delete: Вы уверены? + emails: Список Email processing: Обрабатывается... downloads: @@ -428,9 +425,6 @@ ru: saved: Пользователь успешно сохранен save_error: Не удалось сохранить данные о пользователе destroyed: Учетная запись успешно удалена - emails: - saved: Список еmail успешно сохранен - error: Такой email уже используется group: saved: Группа успешно сохранена diff --git a/config/routes.rb b/config/routes.rb index 671ffa1f9..318af8f5f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,9 @@ Rosa::Application.routes.draw do resources :users do resources :groups, :only => [:new, :create, :index] + resources :emails, :only => [:index, :destroy], :controller => :user_emails do + put :update, :as => :member + end get :autocomplete_user_uname, :on => :collection namespace :settings do @@ -15,9 +18,6 @@ Rosa::Application.routes.draw do end end - match 'users/:id/emails' => 'user_emails#edit', :as => :edit_user_emails, :via => :get, :action => :edit - match 'users/:id/emails' => 'user_emails#update', :as => :update_user_emails, :via => :put, :action => :update - resources :event_logs, :only => :index #resources :downloads, :only => :index diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index c36001a03..e39f6e1b1 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -341,7 +341,7 @@ describe Comment do context 'for committer' do it 'should send an e-mail' do ActionMailer::Base.deliveries = [] - @stranger.emails.first.update_attribute :email, 'code@tpope.net' + @stranger.update_attribute :email, 'code@tpope.net' comment = Comment.create(:user => @user, :body => 'hello!', :project => @project, :commentable_type => @commit.class.name, :commentable_id => @commit.id) ActionMailer::Base.deliveries.count.should == 1 @@ -350,7 +350,7 @@ describe Comment do it 'should send an e-mail with user locale' do ActionMailer::Base.deliveries = [] - @stranger.emails.first.update_attribute :email, 'code@tpope.net' + @stranger.update_attribute :email, 'code@tpope.net' @stranger.update_attribute :language, 'ru' comment = Comment.create(:user => @user, :body => 'hello!', :project => @project, :commentable_type => @commit.class.name, :commentable_id => @commit.id) @@ -362,7 +362,7 @@ describe Comment do it 'should send a one e-mail when subscribed to commit' do ActionMailer::Base.deliveries = [] Subscribe.set_subscribe_to_commit({:project_id => @project.id, :subscribeable_id => @commit.id, :subscribeable_type => @commit.class.name, :user_id => @stranger.id}, Subscribe::ON) - @stranger.emails.first.update_attribute :email, 'code@tpope.net' + @stranger.update_attribute :email, 'code@tpope.net' comment = Comment.create(:user => @user, :body => 'hello!', :project => @project, :commentable_type => @commit.class.name, :commentable_id => @commit.id) ActionMailer::Base.deliveries.count.should == 1 @@ -372,7 +372,7 @@ describe Comment do it 'should not send an e-mail for own comment' do ActionMailer::Base.deliveries = [] #@project.owner.notifier.update_attribute :can_notify, false - @stranger.emails.first.update_attribute :email, 'code@tpope.net' + @stranger.update_attribute :email, 'code@tpope.net' comment = Comment.create(:user => @stranger, :body => 'hello!', :project => @project, :commentable_type => @commit.class.name, :commentable_id => @commit.id) ActionMailer::Base.deliveries.count.should == 1 @@ -382,7 +382,7 @@ describe Comment do it 'should not send an e-mail if global notify off' do ActionMailer::Base.deliveries = [] @project.owner.notifier.update_attribute :can_notify, false - @stranger.emails.first.update_attribute :email, 'code@tpope.net' + @stranger.update_attribute :email, 'code@tpope.net' @stranger.notifier.update_attribute :can_notify, false comment = Comment.create(:user => @user, :body => 'hello!', :project => @project, :commentable_type => @commit.class.name, :commentable_id => @commit.id) @@ -392,7 +392,7 @@ describe Comment do it 'should not send an e-mail if notify for my commits off' do ActionMailer::Base.deliveries = [] @stranger.notifier.update_attribute :new_comment_commit_owner, false - @stranger.emails.first.update_attribute :email, 'code@tpope.net' + @stranger.update_attribute :email, 'code@tpope.net' comment = Comment.create(:user => @user, :body => 'hello!', :project => @project, :commentable_type => @commit.class.name, :commentable_id => @commit.id) ActionMailer::Base.deliveries.count.should == 0