invitation 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -3
- data/app/controllers/invitation/invites_controller.rb +19 -26
- data/app/mailers/invite_mailer.rb +2 -1
- data/app/models/invite.rb +1 -3
- data/config/locales/invitation.pt-BR.yml +25 -0
- data/lib/generators/invitation/controllers/controllers_generator.rb +1 -2
- data/lib/generators/invitation/helpers.rb +4 -9
- data/lib/generators/invitation/install/install_generator.rb +9 -7
- data/lib/generators/invitation/routes/routes_generator.rb +1 -5
- data/lib/generators/invitation/views/views_generator.rb +1 -2
- data/lib/invitation/configuration.rb +9 -9
- data/lib/invitation/engine.rb +12 -2
- data/lib/invitation/invitable.rb +33 -37
- data/lib/invitation/user.rb +16 -19
- data/lib/invitation/user_registration.rb +6 -16
- data/lib/invitation/version.rb +1 -1
- data/lib/invitation.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e20a99422f6cce4d604222b2601932e9e17d22bb
|
4
|
+
data.tar.gz: 2023d2902bc93ce71c2c93387e9e6b786cc64a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a019005b6db16afa6a8610eff17c1009167563bea2f90745482d066a920a426ad1f7889b03d9e6000a03453195884d5a5bfed8b0d69cc2f13402b77ee5a570
|
7
|
+
data.tar.gz: c0ad381f8bfbf5f98738ad3037f60c5bea143c74b38eca27b8df540c5bfa46d3511dd51918f8f77cf4054963ba06fb86037600496c2259110d1b1f0c056cf015
|
data/Rakefile
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
2
7
|
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
11
|
+
load 'rails/tasks/engine.rake'
|
3
12
|
require 'rspec/core/rake_task'
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
13
|
|
6
|
-
|
14
|
+
desc 'Run all specs in spec directory (excluding plugin specs)'
|
15
|
+
task default: :spec
|
@@ -8,48 +8,49 @@
|
|
8
8
|
#
|
9
9
|
# Common extensions include:
|
10
10
|
# * add authorization checks: subclass and add before_actions to :new and :create.
|
11
|
-
# * override after_invite_existing_user or after_invite_new_user
|
11
|
+
# * override after_invite_existing_user or after_invite_new_user
|
12
12
|
#
|
13
13
|
class Invitation::InvitesController < ApplicationController
|
14
|
-
|
15
14
|
def new
|
16
15
|
@invite = InviteForm.new(invite_params)
|
17
16
|
render template: 'invites/new'
|
18
17
|
end
|
19
18
|
|
20
|
-
#
|
19
|
+
# Create one or more Invite instances.
|
20
|
+
# invite: { invitable_id, invitable_type, email or emails:[] }
|
21
|
+
#
|
21
22
|
def create
|
22
23
|
failures = []
|
23
24
|
invites = InviteForm.new(invite_params).build_invites(current_user)
|
24
25
|
ActiveRecord::Base.transaction do
|
25
|
-
invites.each{ |invite| invite.save ? do_invite(invite) : failures << invite.email }
|
26
|
+
invites.each { |invite| invite.save ? do_invite(invite) : failures << invite.email }
|
26
27
|
end
|
27
28
|
|
28
29
|
respond_to do |format|
|
29
|
-
format.html
|
30
|
+
format.html do
|
30
31
|
if failures.empty?
|
31
32
|
flash[:notice] = t('invitation.flash.invite_issued', count: invites.count)
|
32
33
|
else
|
33
34
|
flash[:error] = t('invitation.flash.invite_error', count: failures.count, email: failures.to_sentence)
|
34
35
|
end
|
35
|
-
redirect_to url_after_invite(invites.first) # FIXME
|
36
|
-
|
37
|
-
format.json
|
36
|
+
redirect_to url_after_invite(invites.first) # FIXME: redirect to back
|
37
|
+
end
|
38
|
+
format.json do
|
38
39
|
if failures.empty?
|
39
40
|
# If we received a single email, json response should be a scalar, not an array.
|
40
|
-
invites = params[:invite].
|
41
|
+
invites = params[:invite].key?('email') ? invites.first : invites
|
41
42
|
render json: invites.as_json(except: [:token, :created_at, :updated_at]), status: 201
|
42
43
|
else
|
43
|
-
render json:{
|
44
|
-
|
44
|
+
render json: {
|
45
|
+
message: t('invitation.flash.invite_error', count: failures.count, email: failures.to_sentence),
|
46
|
+
status: :unprocessable_entity
|
47
|
+
}
|
45
48
|
end
|
46
|
-
|
49
|
+
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
+
private
|
53
54
|
|
54
55
|
# A form object pretends to be 'invite', but accepts both 'email' and 'emails'.
|
55
56
|
# It knows how to build all of the invite instances.
|
@@ -72,8 +73,9 @@ class Invitation::InvitesController < ApplicationController
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def build_invites(current_user)
|
75
|
-
all_emails.reject
|
76
|
-
Invite.new(invitable_id: @invitable_id, invitable_type: @invitable_type, sender_id: current_user.id, email: e)
|
76
|
+
all_emails.reject(&:blank?).collect do |e|
|
77
|
+
Invite.new(invitable_id: @invitable_id, invitable_type: @invitable_type, sender_id: current_user.id, email: e)
|
78
|
+
end
|
77
79
|
end
|
78
80
|
|
79
81
|
private
|
@@ -83,10 +85,6 @@ class Invitation::InvitesController < ApplicationController
|
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
|
90
88
|
# Override this if you want to do something more complicated for existing users.
|
91
89
|
# For example, if you have a more complex permissions scheme than just a simple
|
92
90
|
# has_many relationship, enable it here.
|
@@ -95,20 +93,17 @@ class Invitation::InvitesController < ApplicationController
|
|
95
93
|
invite.invitable.add_invited_user(invite.recipient)
|
96
94
|
end
|
97
95
|
|
98
|
-
|
99
96
|
# Override if you want to do something more complicated for new users.
|
100
97
|
# By default we don't do anything extra.
|
101
98
|
def after_invite_new_user(invite)
|
102
99
|
end
|
103
100
|
|
104
|
-
|
105
101
|
# After an invite is created, redirect the user here.
|
106
102
|
# Default implementation doesn't return a url, just the invitable.
|
107
103
|
def url_after_invite(invite)
|
108
104
|
invite.invitable
|
109
105
|
end
|
110
106
|
|
111
|
-
|
112
107
|
def invite_params
|
113
108
|
params[:invite] ? params.require(:invite).permit(:invitable_id, :invitable_type, :email, emails: []) : {}
|
114
109
|
end
|
@@ -127,7 +122,6 @@ class Invitation::InvitesController < ApplicationController
|
|
127
122
|
end
|
128
123
|
end
|
129
124
|
|
130
|
-
|
131
125
|
# Use deliver_later from rails 4.2+ if available.
|
132
126
|
def deliver_email(mail)
|
133
127
|
if mail.respond_to?(:deliver_later)
|
@@ -136,5 +130,4 @@ class Invitation::InvitesController < ApplicationController
|
|
136
130
|
mail.deliver
|
137
131
|
end
|
138
132
|
end
|
139
|
-
|
140
133
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# Send invitations to new and existing users.
|
1
2
|
class InviteMailer < ActionMailer::Base
|
2
3
|
def existing_user(invite)
|
3
4
|
@invite = invite
|
@@ -10,7 +11,7 @@ class InviteMailer < ActionMailer::Base
|
|
10
11
|
|
11
12
|
def new_user(invite)
|
12
13
|
@invite = invite
|
13
|
-
@user_registration_url = Invitation.configuration.user_registration_url.call(:
|
14
|
+
@user_registration_url = Invitation.configuration.user_registration_url.call(invite_token: @invite.token)
|
14
15
|
mail(
|
15
16
|
from: Invitation.configuration.mailer_sender,
|
16
17
|
to: @invite.email,
|
data/app/models/invite.rb
CHANGED
@@ -24,8 +24,6 @@ class Invite < ActiveRecord::Base
|
|
24
24
|
|
25
25
|
def check_recipient_existence
|
26
26
|
recipient = Invitation.configuration.user_model.find_by_email(email)
|
27
|
-
if recipient
|
28
|
-
self.recipient_id = recipient.id
|
29
|
-
end
|
27
|
+
self.recipient_id = recipient.id if recipient
|
30
28
|
end
|
31
29
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
pt-BR:
|
2
|
+
activerecord:
|
3
|
+
attributes:
|
4
|
+
invite:
|
5
|
+
email: "Email"
|
6
|
+
invitation:
|
7
|
+
flash:
|
8
|
+
invite_issued:
|
9
|
+
one: "Problema no convite"
|
10
|
+
other: "Problemas nos convites"
|
11
|
+
invite_error:
|
12
|
+
one: "Não foi possível enviar um convite para %{email}"
|
13
|
+
other: "Não foi possível enviar convites para %{email}"
|
14
|
+
invite_mailer:
|
15
|
+
existing_user:
|
16
|
+
subject: "Instruções do convite"
|
17
|
+
hello: "Olá %{email}"
|
18
|
+
someone_invited_you: "%{sender} convidou você para %{invitable} em %{url}. Agora você tem permissões para acessar com a url a seguir."
|
19
|
+
ignore: "Se as suas permissões não foram adicionadas ou se você sentir que este é um erro, por favor, entre em contato com %{sender}."
|
20
|
+
new_user:
|
21
|
+
subject: "Instruções do convite"
|
22
|
+
hello: "Olá %{email}"
|
23
|
+
someone_invited_you: "%{sender} convidou você para %{invitable} em %{url}. Agora você tem permissões para acessar com a url a seguir."
|
24
|
+
accept: "Aceitar o convite"
|
25
|
+
ignore: "Se você não deseja aceitar este convite, por favor, ignore este email. Sua conta não será criada até você acessar o link a seguir e criar a sua conta."
|
@@ -6,7 +6,7 @@ require 'rails/generators/base'
|
|
6
6
|
module Invitation
|
7
7
|
module Generators
|
8
8
|
class ControllersGenerator < Rails::Generators::Base
|
9
|
-
source_root File.expand_path(
|
9
|
+
source_root File.expand_path('../../../../..', __FILE__)
|
10
10
|
|
11
11
|
def create_controllers
|
12
12
|
directory 'app/controllers'
|
@@ -15,7 +15,6 @@ module Invitation
|
|
15
15
|
def create_mailers
|
16
16
|
directory 'app/mailers'
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
@@ -21,7 +21,7 @@ module Invitation
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def namespaced?
|
24
|
-
|
24
|
+
!namespace.nil?
|
25
25
|
end
|
26
26
|
|
27
27
|
def model_name
|
@@ -57,22 +57,17 @@ module Invitation
|
|
57
57
|
@file_name = @class_path.pop
|
58
58
|
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
def invitable_file_path invitable_class_name
|
60
|
+
def invitable_file_path(invitable_class_name)
|
65
61
|
File.join('app', 'models', "#{invitable_model_name(invitable_class_name).underscore}.rb")
|
66
62
|
end
|
67
63
|
|
68
|
-
def invitable_model_name
|
64
|
+
def invitable_model_name(invitable_class_name)
|
69
65
|
if namespaced?
|
70
66
|
[namespace.to_s] + [invitable_class_name.classify]
|
71
67
|
else
|
72
68
|
[invitable_class_name.classify]
|
73
69
|
end.join('::')
|
74
70
|
end
|
75
|
-
|
76
71
|
end
|
77
72
|
end
|
78
|
-
end
|
73
|
+
end
|
@@ -10,7 +10,10 @@ module Invitation
|
|
10
10
|
|
11
11
|
source_root File.expand_path('../templates', __FILE__)
|
12
12
|
|
13
|
-
class_option :model,
|
13
|
+
class_option :model,
|
14
|
+
optional: true,
|
15
|
+
type: :string,
|
16
|
+
banner: 'model',
|
14
17
|
desc: "Specify the model class name if you will use anything other than 'User'"
|
15
18
|
|
16
19
|
# class_option :invitable, optional: true, type: :array, banner: 'invitable',
|
@@ -54,16 +57,16 @@ module Invitation
|
|
54
57
|
copy_file 'invitation.rb', 'config/initializers/invitation.rb'
|
55
58
|
if options[:model]
|
56
59
|
inject_into_file(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
'config/initializers/invitation.rb',
|
61
|
+
" config.user_model = '#{options[:model]}' \n",
|
62
|
+
after: "Invitation.configure do |config|\n"
|
60
63
|
)
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
|
-
|
67
|
+
protected
|
65
68
|
|
66
|
-
def copy_migration
|
69
|
+
def copy_migration(migration_name)
|
67
70
|
migration_template "db/migrate/#{migration_name}", "db/migrate/#{migration_name}"
|
68
71
|
end
|
69
72
|
|
@@ -71,7 +74,6 @@ module Invitation
|
|
71
74
|
def self.next_migration_number(dir)
|
72
75
|
ActiveRecord::Generators::Base.next_migration_number(dir)
|
73
76
|
end
|
74
|
-
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
@@ -3,7 +3,6 @@ require 'rails/generators/base'
|
|
3
3
|
module Invitation
|
4
4
|
module Generators
|
5
5
|
class RoutesGenerator < Rails::Generators::Base
|
6
|
-
|
7
6
|
source_root File.expand_path('../templates', __FILE__)
|
8
7
|
|
9
8
|
def add_invitation_routes
|
@@ -14,14 +13,12 @@ module Invitation
|
|
14
13
|
inject_into_file(
|
15
14
|
'config/initializers/invitation.rb',
|
16
15
|
" config.routes = false \n",
|
17
|
-
after: "Invitation.configure do |config|\n"
|
16
|
+
after: "Invitation.configure do |config|\n"
|
18
17
|
)
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
20
|
private
|
23
21
|
|
24
|
-
|
25
22
|
def invitation_routes
|
26
23
|
File.read(routes_file_path)
|
27
24
|
end
|
@@ -29,7 +26,6 @@ module Invitation
|
|
29
26
|
def routes_file_path
|
30
27
|
File.expand_path(find_in_source_paths('routes.rb'))
|
31
28
|
end
|
32
|
-
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -6,7 +6,7 @@ require 'rails/generators/base'
|
|
6
6
|
module Invitation
|
7
7
|
module Generators
|
8
8
|
class ViewsGenerator < Rails::Generators::Base
|
9
|
-
source_root File.expand_path(
|
9
|
+
source_root File.expand_path('../../../../..', __FILE__)
|
10
10
|
|
11
11
|
def create_views
|
12
12
|
directory 'app/views'
|
@@ -15,7 +15,6 @@ module Invitation
|
|
15
15
|
def create_locales
|
16
16
|
directory 'config/locales'
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
@@ -1,13 +1,19 @@
|
|
1
|
+
# Invitation requires configuration.#
|
1
2
|
module Invitation
|
3
|
+
# Configure the invitation module. Invoke from a rails initializer.
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# Invitation.configure do |config|
|
7
|
+
# config.user_registration_path = ->(params) { new_profile_path(param) }
|
8
|
+
# end
|
9
|
+
#
|
2
10
|
class Configuration
|
3
|
-
|
4
11
|
# ActiveRecord model class name that represents your user.
|
5
12
|
#
|
6
13
|
# Defaults to '::User'.
|
7
14
|
# @return [ActiveRecord::Base]
|
8
15
|
attr_accessor :user_model
|
9
16
|
|
10
|
-
|
11
17
|
# Url for new users to register for your application. New users are invited to
|
12
18
|
# sign up at this url via email. The url should be expressed as a lambda that
|
13
19
|
# accepts one argument, a params hash. This hash will contain the invitation token.
|
@@ -19,7 +25,6 @@ module Invitation
|
|
19
25
|
# @return [Lambda]
|
20
26
|
attr_accessor :user_registration_url
|
21
27
|
|
22
|
-
|
23
28
|
# Controls the 'from' address for Invitation emails.
|
24
29
|
# Set this to a value appropriate to your application.
|
25
30
|
#
|
@@ -28,7 +33,6 @@ module Invitation
|
|
28
33
|
# @return [String]
|
29
34
|
attr_accessor :mailer_sender
|
30
35
|
|
31
|
-
|
32
36
|
# Enable or disable Invitation's built-in routes.
|
33
37
|
#
|
34
38
|
# Defaults to 'true'.
|
@@ -41,9 +45,8 @@ module Invitation
|
|
41
45
|
# @return [Boolean]
|
42
46
|
attr_accessor :routes
|
43
47
|
|
44
|
-
|
45
48
|
def initialize
|
46
|
-
@user_model = ::User
|
49
|
+
@user_model = ::User if defined?(::User)
|
47
50
|
@user_registration_url = ->(params) { Rails.application.routes.url_helpers.sign_up_url(params) }
|
48
51
|
@mailer_sender = 'reply@example.com'
|
49
52
|
@routes = true
|
@@ -61,10 +64,8 @@ module Invitation
|
|
61
64
|
def routes_enabled?
|
62
65
|
@routes
|
63
66
|
end
|
64
|
-
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
69
|
def self.configuration
|
69
70
|
@configuration ||= Configuration.new
|
70
71
|
end
|
@@ -76,5 +77,4 @@ module Invitation
|
|
76
77
|
def self.configure
|
77
78
|
yield configuration
|
78
79
|
end
|
79
|
-
|
80
80
|
end
|
data/lib/invitation/engine.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
module Invitation
|
2
|
+
# Make invitation available to Rails apps on initialization.
|
3
|
+
#
|
4
|
+
# Requiring `invitation` (likely by having it in your `Gemfile`) will
|
5
|
+
# automatically require the engine.
|
6
|
+
#
|
7
|
+
# Invitation provides:
|
8
|
+
# * routes
|
9
|
+
# * controllers
|
10
|
+
# * views
|
11
|
+
#
|
12
|
+
# You can opt-out of Invitation's internal routes by using {Configuration#routes=}. You can
|
13
|
+
# subclass controllers, and override the Invitation views by running `rails generate invitation:views`.
|
2
14
|
class Engine < ::Rails::Engine
|
3
|
-
|
4
15
|
config.generators do |g|
|
5
16
|
g.test_framework :rspec
|
6
17
|
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
7
18
|
end
|
8
|
-
|
9
19
|
end
|
10
20
|
end
|
data/lib/invitation/invitable.rb
CHANGED
@@ -1,64 +1,60 @@
|
|
1
|
-
#
|
2
|
-
# Any model you wish to invite users to join should extend this concern. This is typically an
|
3
|
-
# organization or resource with limited membership like an "account" or "project".
|
4
|
-
#
|
5
|
-
# Your code is responsible for managing associations between your Invitable and your user model.
|
6
|
-
#
|
7
|
-
# For example, to make the model class Account an organization that can receive an invitation
|
8
|
-
#
|
9
|
-
# class Account < ActiveRecord::Base
|
10
|
-
# invitable named_by: :name
|
11
|
-
#
|
12
|
-
# has_many :account_memberships
|
13
|
-
# has_many :users, through: :account_memberships
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
#
|
17
1
|
module Invitation
|
2
|
+
#
|
3
|
+
# Any model you wish to invite users to join should extend this concern. This is typically an
|
4
|
+
# organization or resource with limited membership like an "account" or "project".
|
5
|
+
#
|
6
|
+
# Your code is responsible for managing associations between your Invitable and your user model.
|
7
|
+
#
|
8
|
+
# For example, to make the model class Account an organization that can receive an invitation
|
9
|
+
#
|
10
|
+
# class Account < ActiveRecord::Base
|
11
|
+
# invitable named_by: :name
|
12
|
+
#
|
13
|
+
# has_many :account_memberships
|
14
|
+
# has_many :users, through: :account_memberships
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
#
|
18
18
|
module Invitable
|
19
|
-
|
19
|
+
# All resources or organizations should be invitable.
|
20
|
+
#
|
21
|
+
# @param [Hash] options - either named_by: <method name> or named: <String>
|
20
22
|
def invitable(options = {})
|
21
23
|
has_many :invites, as: :invitable
|
22
24
|
class_attribute :invitable_options
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
raise <<-eos
|
30
|
-
invitable requires options be set, either :name or :named_by.
|
31
|
-
invitable named: "string"
|
32
|
-
or
|
33
|
-
invitable named_by: :method_name
|
34
|
-
eos
|
25
|
+
self.invitable_options = {}
|
26
|
+
case
|
27
|
+
when options[:named_by] then invitable_options[:named_by] = options[:named_by]
|
28
|
+
when options[:named] then invitable_options[:named] = options[:named]
|
29
|
+
else raise 'invitable requires options be set, either :name or :named_by. \
|
30
|
+
e.g.: `invitable named: "string"` or `invitable named_by: :method_name`'
|
35
31
|
end
|
36
|
-
|
37
32
|
include Invitation::Invitable::InstanceMethods
|
38
33
|
end
|
39
34
|
|
40
|
-
|
35
|
+
# Instance methods for invitables.
|
41
36
|
module InstanceMethods
|
42
|
-
|
37
|
+
#
|
43
38
|
# Add the invited user to the organization. Called by InvitesController.
|
39
|
+
#
|
44
40
|
def add_invited_user(user)
|
45
41
|
method = Invitation.configuration.user_model.name.underscore.pluralize
|
46
|
-
|
42
|
+
send(method).push(user)
|
47
43
|
end
|
48
44
|
|
45
|
+
#
|
49
46
|
# Get the name of the organization for use in invitations.
|
47
|
+
#
|
50
48
|
def invitable_name
|
51
49
|
if invitable_options[:named_by]
|
52
|
-
|
50
|
+
send(invitable_options[:named_by])
|
53
51
|
elsif invitable_options[:named]
|
54
52
|
invitable_options[:named]
|
55
53
|
else
|
56
54
|
raise 'Invitation runtime error: invitable does not have name: or named_by: set, should not be possible! ' +
|
57
|
-
|
55
|
+
inspect
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
61
|
-
|
62
59
|
end
|
63
60
|
end
|
64
|
-
|
data/lib/invitation/user.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
#
|
2
|
-
# Your user model must include this concern to send and receive invitations. Your user class must also be
|
3
|
-
# specified in the invitation configuration `Invitation.configure.user_model`.
|
4
|
-
#
|
5
|
-
# Your user model code is responsible for managing associations to any organizations you wish
|
6
|
-
# to issue invitations to. Your user model will probably also include an authentication model.
|
7
|
-
#
|
8
|
-
# For example, to make your user class `User` able to issue invitations to model `Account`:
|
9
|
-
#
|
10
|
-
# class User < ActiveRecord::Base
|
11
|
-
# include Invitation::User
|
12
|
-
# include Authenticate::User
|
13
|
-
#
|
14
|
-
# has_many :account_memberships
|
15
|
-
# has_many :accounts, through: :account_memberships
|
16
|
-
# end
|
17
|
-
#
|
18
1
|
module Invitation
|
2
|
+
# Your user model must include this concern to send and receive invitations. Your user class must also be
|
3
|
+
# specified in the invitation configuration `Invitation.configure.user_model`.
|
4
|
+
#
|
5
|
+
# Your user model code is responsible for managing associations to any organizations you wish
|
6
|
+
# to issue invitations to. Your user model will probably also include an authentication model.
|
7
|
+
#
|
8
|
+
# For example, to make your user class `User` able to issue invitations to model `Account`:
|
9
|
+
#
|
10
|
+
# class User < ActiveRecord::Base
|
11
|
+
# include Invitation::User
|
12
|
+
# include Authenticate::User
|
13
|
+
#
|
14
|
+
# has_many :account_memberships
|
15
|
+
# has_many :accounts, through: :account_memberships
|
16
|
+
# end
|
17
|
+
#
|
19
18
|
module User
|
20
19
|
extend ActiveSupport::Concern
|
21
20
|
|
@@ -32,7 +31,5 @@ module Invitation
|
|
32
31
|
invite.recipient = self
|
33
32
|
invite.save
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
38
|
-
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# Your user registration controller should include this concern.
|
2
|
-
#
|
3
1
|
module Invitation
|
2
|
+
#
|
3
|
+
# UserRegistration should be included by your user registration controller.
|
4
|
+
#
|
4
5
|
module UserRegistration
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
|
7
|
-
|
8
8
|
# Copy params[:invite_token] to @invite_token. Your user registration form needs
|
9
9
|
# to include :invite_token, this method is the controller half of the glue.
|
10
10
|
#
|
@@ -16,7 +16,6 @@ module Invitation
|
|
16
16
|
@invite_token = params[:invite_token]
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
# Check for an invitation token and process the invite. If an invitation is found, the
|
21
20
|
# user claims the invite.
|
22
21
|
#
|
@@ -28,25 +27,16 @@ module Invitation
|
|
28
27
|
# For example, if your user model is UserProfile, this method will check for @user_profile.
|
29
28
|
#
|
30
29
|
def process_invite_token(new_user = nil)
|
31
|
-
if new_user.nil?
|
32
|
-
new_user = user_instance_variable
|
33
|
-
end
|
34
|
-
|
30
|
+
new_user = user_instance_variable if new_user.nil?
|
35
31
|
token = params[:invite_token]
|
36
|
-
|
37
|
-
new_user.claim_invite token
|
38
|
-
end
|
32
|
+
new_user.claim_invite token if !token.nil? && !new_user.nil?
|
39
33
|
end
|
40
34
|
|
41
|
-
|
42
35
|
private
|
43
36
|
|
44
|
-
|
45
37
|
def user_instance_variable
|
46
38
|
name = Invitation.configuration.user_model_instance_var
|
47
|
-
|
39
|
+
instance_variable_get(name)
|
48
40
|
end
|
49
|
-
|
50
41
|
end
|
51
42
|
end
|
52
|
-
|
data/lib/invitation/version.rb
CHANGED
data/lib/invitation.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invitation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Tomich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- app/views/invite_mailer/new_user.text.erb
|
174
174
|
- app/views/invites/new.html.erb
|
175
175
|
- config/locales/invitation.en.yml
|
176
|
+
- config/locales/invitation.pt-BR.yml
|
176
177
|
- config/routes.rb
|
177
178
|
- lib/generators/invitation/controllers/USAGE
|
178
179
|
- lib/generators/invitation/controllers/controllers_generator.rb
|