Revert "[refs #114] emails control"
This reverts commit 26fb1fcbfb843163231d8b8f0caf582bafccbe57. Conflicts: app/models/subscribe.rb app/models/user.rb spec/models/comment_for_commit_spec.rb
This commit is contained in:
parent
dc39eefe62
commit
f6b6bbfb54
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
|
@ -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}
|
|
@ -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
|
||||
|
|
|
@ -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: Группа успешно сохранена
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue