#637: added migration, updated approve_notification

This commit is contained in:
Vokhmin Alexey V 2012-09-10 15:08:53 +04:00
parent 8c06b0c18d
commit 5f941844f2
7 changed files with 52 additions and 16 deletions

View File

@ -8,6 +8,7 @@ class Users::RegisterRequestsController < ApplicationController
end
def create
params[:register_request][:language] = I18n.locale if params[:register_request]
RegisterRequest.create(params[:register_request])
render :thanks
end

View File

@ -10,7 +10,7 @@ class UserMailer < ActionMailer::Base
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_user_notification", :project_name => APP_CONFIG['project_name'])) do |format|
format.html
end
end
end # new_user_notification
def new_comment_notification(comment, user)
@user = user
@ -18,7 +18,7 @@ class UserMailer < ActionMailer::Base
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_#{comment.commit_comment? ? 'commit_' : ''}comment_notification")) do |format|
format.html
end
end
end # new_comment_notification
def new_issue_notification(issue, user)
@user = user
@ -26,7 +26,7 @@ class UserMailer < ActionMailer::Base
mail(:to => user.email, :subject => I18n.t("notifications.subjects.new_issue_notification")) do |format|
format.html
end
end
end # new_issue_notification
def issue_assign_notification(issue, user)
@user = user
@ -34,10 +34,13 @@ class UserMailer < ActionMailer::Base
mail(:to => user.email, :subject => I18n.t("notifications.subjects.issue_assign_notification")) do |format|
format.html
end
end
end # issue_assign_notification
def invite_approve_notification(register_request)
I18n.locale = register_request.language if register_request.language
@register_request = register_request
mail :to => register_request.email, :subject => I18n.t("notifications.subjects.invite_approve_notification")
end
end
mail :to => register_request.email, :subject => I18n.t("notifications.subjects.invite_approve_notification") do |format|
format.html
end
end # invite_approve_notification
end # UserMailer

View File

@ -1,34 +1,53 @@
# -*- encoding : utf-8 -*-
class RegisterRequest < ActiveRecord::Base
#---------------
# *** Scopes ***
#+++++++++++++++
default_scope order('created_at ASC')
scope :rejected, where(:rejected => true)
scope :approved, where(:approved => true)
scope :unprocessed, where(:approved => false, :rejected => false)
# before_create :generate_token
before_update :invite_approve_notification
#--------------------
# *** Validations ***
#++++++++++++++++++++
validates :email, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
#------------------
# *** Callbacks ***
#++++++++++++++++++
# before_create :generate_token
before_update :invite_approve_notification
#-------------------------
# *** Instance Methods ***
#+++++++++++++++++++++++++
def approve
update_attributes(:approved => true, :rejected => false)
end
end # approve
def reject
update_attributes(:approved => false, :rejected => true)
end
end # reject
protected
def generate_token
self.token = Digest::SHA1.hexdigest(name + email + Time.now.to_s + rand.to_s)
end
end # generate_token
def invite_approve_notification
if approved_changed? and approved == true
puts "!!!!!!!!!!========="
if approved_changed? && approved?
puts "!!!!!!!!!!"
generate_token
UserMailer.invite_approve_notification(self).deliver
end
end
end
end # invite_approve_notification
end # RegisterRequest

View File

@ -0,0 +1,7 @@
%p== Hello, #{@register_request.name || @register_request.email}.
%p
You have been invited to project «ROSA Build System». Please click on the following link for registration:
= link_to 'link', new_user_registration_url(:invitation_token => @register_request.token)
%p== Support team «ROSA Build System»

View File

@ -0,0 +1,5 @@
class AddLanguageToRegisterRequest < ActiveRecord::Migration
def change
add_column :register_requests, :language, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120906115648) do
ActiveRecord::Schema.define(:version => 20120910094748) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -351,6 +351,7 @@ ActiveRecord::Schema.define(:version => 20120906115648) do
t.datetime "updated_at"
t.string "interest"
t.text "more"
t.string "language"
end
add_index "register_requests", ["email"], :name => "index_register_requests_on_email", :unique => true, :case_sensitive => false