[refs #114] user emails
This commit is contained in:
parent
651c5637ed
commit
77420d2a8f
|
@ -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
|
|
@ -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|
|
||||
|
|
|
@ -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_]+$/ }
|
||||
|
@ -41,7 +43,7 @@ class User < ActiveRecord::Base
|
|||
def admin?
|
||||
role == 'admin'
|
||||
end
|
||||
|
||||
|
||||
def guest?
|
||||
self.id.blank? # persisted?
|
||||
end
|
||||
|
@ -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)
|
||||
|
@ -82,7 +86,7 @@ class User < ActiveRecord::Base
|
|||
clean_up_passwords
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def create_settings_notifier
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class UserEmail < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
validates :email, :uniqueness => true
|
||||
validates :email, :presence => true
|
||||
|
||||
end
|
|
@ -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"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
en:
|
||||
will_paginate:
|
||||
previous_label: ‹ Previous!!!
|
||||
previous_label: ‹ Previous!!!
|
||||
next_label: Next ›
|
||||
page_gap: ...
|
||||
|
||||
|
||||
datatables:
|
||||
previous_label: ‹ Prev.
|
||||
next_label: Next ›b r
|
||||
|
@ -44,6 +44,7 @@ en:
|
|||
notifier: Notifier setting
|
||||
notifiers:
|
||||
edit_header: Notifier setting
|
||||
email: Email addresses
|
||||
processing: working ...
|
||||
|
||||
downloads:
|
||||
|
@ -690,4 +691,4 @@ en:
|
|||
new_comment_notification: New comment to your task
|
||||
new_issue_notification: New task added to project
|
||||
new_user_notification: Registered on project «%{ project_name }»
|
||||
issue_assign_notification: New task assigned
|
||||
issue_assign_notification: New task assigned
|
||||
|
|
|
@ -44,6 +44,7 @@ ru:
|
|||
notifier: Настройки оповещений
|
||||
notifiers:
|
||||
edit_header: Настройки оповещений
|
||||
emails: Список Email
|
||||
processing: Обрабатывается...
|
||||
|
||||
downloads:
|
||||
|
@ -680,14 +681,14 @@ ru:
|
|||
status: Статус
|
||||
version: Версия
|
||||
build_list: Сборочный лист
|
||||
|
||||
|
||||
download:
|
||||
name: Название
|
||||
version: Версия
|
||||
distro: Дистрибутив
|
||||
platform: Архитектура
|
||||
counter: Закачки
|
||||
|
||||
|
||||
notifications:
|
||||
subjects:
|
||||
new_comment_notification: Новый комментарий к Вашей задаче
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
16
db/schema.rb
16
db/schema.rb
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe UserEmail do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue