[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 subscribes = comment.commentable.subscribes if commentable_class == Issue
if commentable_class == Grit::Commit if commentable_class == Grit::Commit
subscribes = comment.project.commit_comments_subscribes(true) # FIXME (true) for rspec 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? 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 end
subscribes.each do |subscribe| 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 :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :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 include Modules::Models::PersonalRepository
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ }
@ -41,7 +43,7 @@ class User < ActiveRecord::Base
def admin? def admin?
role == 'admin' role == 'admin'
end end
def guest? def guest?
self.id.blank? # persisted? self.id.blank? # persisted?
end end
@ -53,7 +55,9 @@ class User < ActiveRecord::Base
def find_for_database_authentication(warden_conditions) def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup conditions = warden_conditions.dup
login = conditions.delete(:login) 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 end
def new_with_session(params, session) def new_with_session(params, session)
@ -82,7 +86,7 @@ class User < ActiveRecord::Base
clean_up_passwords clean_up_passwords
result result
end end
private private
def create_settings_notifier def create_settings_notifier

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 .group.navform.wat-cf
= link_to t('layout.settings.notifier'), user_settings_notifier_path(current_user)#, :class => "text_button_padding link_button" = 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

@ -1,9 +1,9 @@
en: en:
will_paginate: will_paginate:
previous_label: Previous!!! previous_label: Previous!!!
next_label: Next next_label: Next
page_gap: ... page_gap: ...
datatables: datatables:
previous_label: Prev. previous_label: Prev.
next_label: Next b r next_label: Next b r
@ -44,6 +44,7 @@ en:
notifier: Notifier setting notifier: Notifier setting
notifiers: notifiers:
edit_header: Notifier setting edit_header: Notifier setting
email: Email addresses
processing: working ... processing: working ...
downloads: downloads:
@ -690,4 +691,4 @@ en:
new_comment_notification: New comment to your task new_comment_notification: New comment to your task
new_issue_notification: New task added to project new_issue_notification: New task added to project
new_user_notification: Registered on project «%{ project_name }» new_user_notification: Registered on project «%{ project_name }»
issue_assign_notification: New task assigned issue_assign_notification: New task assigned

View File

@ -44,6 +44,7 @@ ru:
notifier: Настройки оповещений notifier: Настройки оповещений
notifiers: notifiers:
edit_header: Настройки оповещений edit_header: Настройки оповещений
emails: Список Email
processing: Обрабатывается... processing: Обрабатывается...
downloads: downloads:
@ -680,14 +681,14 @@ ru:
status: Статус status: Статус
version: Версия version: Версия
build_list: Сборочный лист build_list: Сборочный лист
download: download:
name: Название name: Название
version: Версия version: Версия
distro: Дистрибутив distro: Дистрибутив
platform: Архитектура platform: Архитектура
counter: Закачки counter: Закачки
notifications: notifications:
subjects: subjects:
new_comment_notification: Новый комментарий к Вашей задаче new_comment_notification: Новый комментарий к Вашей задаче

View File

@ -8,6 +8,10 @@ Rosa::Application.routes.draw do
resources :users do resources :users do
resources :groups, :only => [:new, :create, :index] 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 get :autocomplete_user_uname, :on => :collection
namespace :settings do namespace :settings do
resource :notifier, :only => [:show, :update] 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. # 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| create_table "arches", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
@ -304,13 +304,25 @@ ActiveRecord::Schema.define(:version => 20120118173141) do
end end
create_table "subscribes", :force => true do |t| create_table "subscribes", :force => true do |t|
t.integer "subscribeable_id" t.string "subscribeable_id"
t.string "subscribeable_type" t.string "subscribeable_type"
t.integer "user_id" t.integer "user_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "status", :default => 1
t.integer "project_id"
end 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| create_table "users", :force => true do |t|
t.string "name" t.string "name"
t.string "email", :default => "", :null => false 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