[CDB-3436] Notif with email within new org user

pull/638/head
Luis Bosque 10 years ago
parent 1cd9fa179e
commit 431c5c0d94

@ -2,6 +2,15 @@ class UserMailer < ActionMailer::Base
default from: "cartodb.com <support@cartodb.com>"
layout 'mail'
def new_organization_user(user)
@user = user
@organization = @user.organization
@owner = @organization.owner
@link = "#{CartoDB.base_url(@organization.name)}#{dashboard_path(user_domain: @user.username)}"
mail :to => @user.email,
:subject => "You have been invited to CartoDB organization '#{@organization.name}'"
end
def share_table(table, user)
@table_visualization = table
@user = user
@ -23,7 +32,6 @@ class UserMailer < ActionMailer::Base
def unshare_table(table_visualization_name, table_visualization_owner_name, user)
@table_visualization_name = table_visualization_name
@table_visualization_owner_name = table_visualization_owner_name
#@table_visualization = table
@user = user
mail :to => @user.email,
:subject => "#{@table_visualization_owner_name} has stopped sharing a CartoDB table with you"
@ -32,7 +40,6 @@ class UserMailer < ActionMailer::Base
def unshare_visualization(visualization_name, visualization_owner_name, user)
@visualization_name = visualization_name
@visualization_owner_name = visualization_owner_name
#@visualization = visualization
@user = user
mail :to => @user.email,
:subject => "#{@visualization_owner_name} has stopped sharing a CartoDB visualization with you"

@ -107,6 +107,9 @@ class User < Sequel::Model
monitor_user_notification
sleep 3
set_statement_timeouts
if self.has_organization_enabled?
::Resque.enqueue(::Resque::UserJobs::Mail::NewOrganizationUser, self.id)
end
end
def after_save
@ -499,7 +502,6 @@ class User < Sequel::Model
end
def cartodb_avatar
puts Cartodb.config[:avatars]
if !Cartodb.config[:avatars].nil? &&
!Cartodb.config[:avatars]['base_url'].nil? && !Cartodb.config[:avatars]['base_url'].empty? &&
!Cartodb.config[:avatars]['kinds'].nil? && !Cartodb.config[:avatars]['kinds'].empty? &&
@ -1611,11 +1613,11 @@ TRIGGER
def drop_user_privileges_in_schema(schema)
in_database(:as => :superuser) do |user_database|
user_database.transaction do
[self.database_user, self.database_public_user].each do |u|
user_database.run("REVOKE ALL ON SCHEMA \"#{schema}\" FROM #{u}")
user_database.run("REVOKE ALL ON ALL SEQUENCES IN SCHEMA \"#{schema}\" FROM #{u}")
user_database.run("REVOKE ALL ON ALL FUNCTIONS IN SCHEMA \"#{schema}\" FROM #{u}")
user_database.run("REVOKE ALL ON ALL TABLES IN SCHEMA \"#{schema}\" FROM #{u}")
[self.database_username, self.database_public_username].each do |u|
user_database.run("REVOKE ALL ON SCHEMA \"#{schema}\" FROM \"#{u}\"")
user_database.run("REVOKE ALL ON ALL SEQUENCES IN SCHEMA \"#{schema}\" FROM \"#{u}\"")
user_database.run("REVOKE ALL ON ALL FUNCTIONS IN SCHEMA \"#{schema}\" FROM \"#{u}\"")
user_database.run("REVOKE ALL ON ALL TABLES IN SCHEMA \"#{schema}\" FROM \"#{u}\"")
end
end
end

@ -0,0 +1,23 @@
<% content_for(:header_color) {"3B7EBB"} %>
<% content_for(:header_img) {"top.png"} %>
<% content_for :body do %>
<p style="text-align: center;">You have been invited to CartoDB as part of the <strong><%= @organization.name %> organization</strong>. From now on you will be able to enter to your CartoDB dashboard by login in with your username (<%= @user.username %>) and the password provided by your administrator.</p>
<table border="0" cellspacing="0" cellpadding="0" style="margin: 0 auto;">
<tr>
<td style="background: url(http://cartodb.s3.amazonaws.com/mails/editor/button-bg.png) no-repeat left; padding: 10px 0; font-size: 16px; width: 21px;">&nbsp;</td>
<td style="background: #407CC0; color:#fff; padding: 10px;">
<a href="<%= @link %>" style="color: #fff; text-decoration: none;">Go to your dashboard</a>
</td>
<td style="background: url(http://cartodb.s3.amazonaws.com/mails/editor/button-bg.png) no-repeat right; padding: 10px 0; font-size: 16px; width: 21px;">&nbsp;</td>
</tr>
<tr>
<td style="height: 20px;">&nbsp;</td>
</tr>
</table>
<p style="text-align: center; font-size: 12px; color: #A8A8A8;">If you have not received your password yet, contact with your administrator at <%= @owner.username %></p>
<% end %>

@ -8,22 +8,38 @@ module CartoDB
def initialize
@pool = {}
end
# Intended only for testing
def all
@pool
end
def fetch(configuration, &block)
conn = nil
if @pool[connection_id(configuration)]
Rails.logger.debug "[pool] Found a connection for #{connection_id(configuration)} (#{@pool.keys.size})"
@pool[connection_id(configuration)][:last_accessed] = Time.now
@pool[connection_id(configuration)][:connection]
conn = @pool[connection_id(configuration)][:connection]
else
if @pool.size >= MAX_POOL_SIZE
#close_connections!
close_oldest_connection!
end
connection = yield
@pool[connection_id(configuration)] = { :connection => connection, :last_accessed => Time.now }
Rails.logger.debug "[pool] Creating a new connection for #{connection_id(configuration)} (#{@pool.keys.size})"
connection
conn = create_new_connection(configuration, &block)
end
# This conn may be still broken after 3 tries
return conn
end
def max_pool_size?
if @pool.size >= MAX_POOL_SIZE
#close_connections!
close_oldest_connection!
end
end
def create_new_connection(configuration, &block)
max_pool_size?
connection = yield
@pool[connection_id(configuration)] = { :connection => connection, :last_accessed => Time.now }
Rails.logger.debug "[pool] Creating a new connection for #{connection_id(configuration)} (#{@pool.keys.size})"
connection
end
def close_connections!(db=nil)

@ -4,7 +4,16 @@ require_relative './base_job'
module Resque
module UserJobs
module Mail
module NewOrganizationUser
@queue = :users
def self.perform(user_id)
u = User.where(id: user_id).first
UserMailer.new_organization_user(u).deliver
end
end
module ShareVisualization
@queue = :users

@ -1034,6 +1034,24 @@ describe User do
end
end
it "should notify a new user created from a organization" do
::Resque.stubs(:enqueue).returns(nil)
organization = FactoryGirl.create(:organization_with_users)
user1 = new_user(:username => 'test', :email => "client@example.com", :password => "clientex")
user1.organization = organization
user1.id = UUIDTools::UUID.timestamp_create.to_s
::Resque.expects(:enqueue).with(::Resque::UserJobs::Mail::NewOrganizationUser, user1.id).once
user1.save
organization.destroy
#user1.destroy
#organization.users.each {|u| u.destroy unless u == organization.owner }
#organization.owner.destroy
end
def create_org(org_name, org_quota, org_seats)
organization = Organization.new

Loading…
Cancel
Save