[refs #114] user emails

This commit is contained in:
Alexander Machehin 2012-01-26 14:53:40 +06:00
parent 651c5637ed
commit 77420d2a8f
13 changed files with 104 additions and 11 deletions

View File

@ -0,0 +1,27 @@
# coding: UTF-8
class UserEmailsController < UsersController
before_filter :find_user
def index
@emails = @user.emails
(5 - @user.emails.count).times {|e| @emails << UserEmail.new(:user_id => @user) }
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
def destroy
@user.destroy
flash[:notice] = t("flash.user.destroyed")
redirect_to users_path
end
end

View File

@ -7,7 +7,7 @@ class Subscribe < ActiveRecord::Base
subscribes = comment.commentable.subscribes if commentable_class == Issue
if commentable_class == Grit::Commit
subscribes = comment.project.commit_comments_subscribes(true) # FIXME (true) for rspec
committer = User.where(:email => comment.commentable.committer.email).first
committer = User.includes(:user_emails).where("user_emails.email = ?", comment.commentable.committer.email).first
UserMailer.delay.new_comment_notification(comment, committer) if committer && !comment.own_comment?(committer) && committer.notifier.new_comment_commit_owner && !committer.notifier.can_notify && subscribes.where(:user_id => committer).empty?
end
subscribes.each do |subscribe|

View File

@ -24,6 +24,8 @@ class User < ActiveRecord::Base
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
has_many :user_emails, :dependent => :destroy, :as => :emails
include Modules::Models::PersonalRepository
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ }
@ -53,7 +55,9 @@ class User < ActiveRecord::Base
def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
where(conditions).where(["lower(uname) = :value OR lower(email) = :value", { :value => login.downcase }]).first
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)",
{:value => login.downcase}).first
end
def new_with_session(params, session)

7
app/models/user_email.rb Normal file
View File

@ -0,0 +1,7 @@
class UserEmail < ActiveRecord::Base
belongs_to :user
validates :email, :uniqueness => true
validates :email, :presence => true
end

View File

@ -76,3 +76,6 @@
.group.navform.wat-cf
= 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"

View File

View File

@ -44,6 +44,7 @@ en:
notifier: Notifier setting
notifiers:
edit_header: Notifier setting
email: Email addresses
processing: working ...
downloads:

View File

@ -44,6 +44,7 @@ ru:
notifier: Настройки оповещений
notifiers:
edit_header: Настройки оповещений
emails: Список Email
processing: Обрабатывается...
downloads:

View File

@ -8,6 +8,10 @@ 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
resource :notifier, :only => [:show, :update]

View File

@ -0,0 +1,21 @@
class CreateUserEmails < ActiveRecord::Migration
def self.up
create_table :user_emails do |t|
t.integer :user_id, :null => false
t.string :email, :null => false
t.timestamps
end
add_index :user_emails, :user_id
add_index :user_emails, :email
UserEmail.reset_column_information
User.all.each do |u|
UserEmail.create(:user_id => u.id, :email => u.email)
end
end
def self.down
drop_table :user_emails
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120118173141) do
ActiveRecord::Schema.define(:version => 20120123161250) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -304,13 +304,25 @@ ActiveRecord::Schema.define(:version => 20120118173141) do
end
create_table "subscribes", :force => true do |t|
t.integer "subscribeable_id"
t.string "subscribeable_id"
t.string "subscribeable_type"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "status", :default => 1
t.integer "project_id"
end
create_table "user_emails", :force => true do |t|
t.integer "user_id", :null => false
t.string "email", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "user_emails", ["email"], :name => "index_user_emails_on_email"
add_index "user_emails", ["user_id"], :name => "index_user_emails_on_user_id"
create_table "users", :force => true do |t|
t.string "name"
t.string "email", :default => "", :null => false

View File

@ -0,0 +1,8 @@
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :user_email do
user_id 1
email "MyString"
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe UserEmail do
pending "add some examples to (or delete) #{__FILE__}"
end