[refs #114] emails control
This commit is contained in:
parent
e04b2eb59b
commit
e71a9e84cb
|
@ -1,27 +1,21 @@
|
|||
# coding: UTF-8
|
||||
class UserEmailsController < UsersController
|
||||
before_filter :find_user
|
||||
class UserEmailsController < ApplicationController
|
||||
layout 'sessions'
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
@emails = @user.emails
|
||||
(5 - @user.emails.count).times {|e| @emails << UserEmail.new(:user_id => @user) }
|
||||
def edit
|
||||
(5 - current_user.emails.count).times {current_user.emails.build }
|
||||
render 'users/emails/emails'
|
||||
end
|
||||
|
||||
def update
|
||||
@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
|
||||
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}
|
||||
|
||||
def destroy
|
||||
@user.destroy
|
||||
flash[:notice] = t("flash.user.destroyed")
|
||||
redirect_to users_path
|
||||
flash[:notice] = t('flash.user.emails.saved')
|
||||
redirect_to edit_user_emails_path
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ class Comment < ActiveRecord::Base
|
|||
self.commentable.subscribes.create(:user_id => self.user_id) 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 << User.where(:email => self.commentable.committer.email).first # commentor and committer
|
||||
recipients << self.user << UserEmail.where(:email => self.commentable.committer.email).first.try(:user) # commentor and committer
|
||||
recipients << self.project.owner if self.project.owner_type == 'User' # project owner
|
||||
recipients.compact.uniq.each {|user| Subscribe.subscribe_user_to_commit(self, user.id)}
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ class Subscribe < ActiveRecord::Base
|
|||
|
||||
def self.subscribed_to_commit?(project, user, commentable)
|
||||
is_commentor = (Comment.where(:commentable_type => commentable.class.name, :commentable_id => commentable.id).exists?(:user_id => user.id))
|
||||
is_committer = (user.email == commentable.committer.email)
|
||||
is_committer = (user.emails.exists? :email => commentable.committer.email)
|
||||
return false if user.subscribes.where(:subscribeable_id => commentable.id, :subscribeable_type => commentable.class.name,
|
||||
:project_id => project.id, :status => Subscribe::OFF).first.present?
|
||||
(project.owner?(user) && user.notifier.new_comment_commit_repo_owner) or
|
||||
|
|
|
@ -25,7 +25,7 @@ class User < ActiveRecord::Base
|
|||
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
|
||||
has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy
|
||||
|
||||
has_many :user_emails, :dependent => :destroy, :as => :emails
|
||||
has_many :emails, :class_name => 'UserEmail', :dependent => :destroy
|
||||
|
||||
include Modules::Models::PersonalRepository
|
||||
|
||||
|
@ -39,7 +39,10 @@ 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'
|
||||
|
@ -57,7 +60,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 users.user_id = m.user_id and lower(m.email) = :value)",
|
||||
"exists (select null from user_emails m where m.user_id = m.user_id and lower(m.email) = :value)",
|
||||
{:value => login.downcase}).first
|
||||
end
|
||||
|
||||
|
@ -94,4 +97,7 @@ 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'), user_emails_path(current_user)#, :class => "text_button_padding link_button"
|
||||
= link_to t('layout.settings.emails'), edit_user_emails_path(current_user.id)#, :class => "text_button_padding link_button"
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
= 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"
|
|
@ -0,0 +1,5 @@
|
|||
#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,7 +45,10 @@ en:
|
|||
notifier: Notifier setting
|
||||
notifiers:
|
||||
edit_header: Notifier setting
|
||||
email: Email addresses
|
||||
email:
|
||||
list: Email addresses
|
||||
delete: Destroy
|
||||
confirm_delete: Are you sure?
|
||||
processing: working ...
|
||||
|
||||
downloads:
|
||||
|
@ -430,7 +433,9 @@ 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,7 +44,10 @@ ru:
|
|||
notifier: Настройки оповещений
|
||||
notifiers:
|
||||
edit_header: Настройки оповещений
|
||||
emails: Список Email
|
||||
email:
|
||||
list: Список Email
|
||||
delete: Удалить
|
||||
confirm_delete: Вы уверены?
|
||||
processing: Обрабатывается...
|
||||
|
||||
downloads:
|
||||
|
@ -425,6 +428,9 @@ ru:
|
|||
saved: Пользователь успешно сохранен
|
||||
save_error: Не удалось сохранить данные о пользователе
|
||||
destroyed: Учетная запись успешно удалена
|
||||
emails:
|
||||
saved: Список еmail успешно сохранен
|
||||
error: Такой email уже используется
|
||||
|
||||
group:
|
||||
saved: Группа успешно сохранена
|
||||
|
|
|
@ -8,9 +8,6 @@ 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
|
||||
|
@ -18,6 +15,9 @@ 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.update_attribute :email, 'code@tpope.net'
|
||||
@stranger.emails.first.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.update_attribute :email, 'code@tpope.net'
|
||||
@stranger.emails.first.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, @commit, @stranger.id, Subscribe::ON)
|
||||
@stranger.update_attribute :email, 'code@tpope.net'
|
||||
@stranger.emails.first.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.update_attribute :email, 'code@tpope.net'
|
||||
@stranger.emails.first.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.update_attribute :email, 'code@tpope.net'
|
||||
@stranger.emails.first.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.update_attribute :email, 'code@tpope.net'
|
||||
@stranger.emails.first.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