From 5f941844f2caff76d554831aecbaeae84fd29dc4 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 10 Sep 2012 15:08:53 +0400 Subject: [PATCH] #637: added migration, updated approve_notification --- .../users/register_requests_controller.rb | 1 + app/mailers/user_mailer.rb | 17 +++++---- app/models/register_request.rb | 35 ++++++++++++++----- .../invite_approve_notification.en.haml | 7 ++++ ...ml => invite_approve_notification.ru.haml} | 0 ...094748_add_language_to_register_request.rb | 5 +++ db/schema.rb | 3 +- 7 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 app/views/user_mailer/invite_approve_notification.en.haml rename app/views/user_mailer/{invite_approve_notification.html.haml => invite_approve_notification.ru.haml} (100%) create mode 100644 db/migrate/20120910094748_add_language_to_register_request.rb diff --git a/app/controllers/users/register_requests_controller.rb b/app/controllers/users/register_requests_controller.rb index 234ef39ab..a21249cdb 100644 --- a/app/controllers/users/register_requests_controller.rb +++ b/app/controllers/users/register_requests_controller.rb @@ -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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index e19cb799f..a2793f64c 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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 diff --git a/app/models/register_request.rb b/app/models/register_request.rb index 972dc1029..ec13b6c8b 100644 --- a/app/models/register_request.rb +++ b/app/models/register_request.rb @@ -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 diff --git a/app/views/user_mailer/invite_approve_notification.en.haml b/app/views/user_mailer/invite_approve_notification.en.haml new file mode 100644 index 000000000..cbd3adeb8 --- /dev/null +++ b/app/views/user_mailer/invite_approve_notification.en.haml @@ -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» diff --git a/app/views/user_mailer/invite_approve_notification.html.haml b/app/views/user_mailer/invite_approve_notification.ru.haml similarity index 100% rename from app/views/user_mailer/invite_approve_notification.html.haml rename to app/views/user_mailer/invite_approve_notification.ru.haml diff --git a/db/migrate/20120910094748_add_language_to_register_request.rb b/db/migrate/20120910094748_add_language_to_register_request.rb new file mode 100644 index 000000000..56b2dcfbd --- /dev/null +++ b/db/migrate/20120910094748_add_language_to_register_request.rb @@ -0,0 +1,5 @@ +class AddLanguageToRegisterRequest < ActiveRecord::Migration + def change + add_column :register_requests, :language, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index e9375ad5d..b03e33f0b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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