invitation 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +144 -0
- data/CONTRIBUTING.md +59 -0
- data/LICENSE +20 -0
- data/README.md +378 -0
- data/lib/generators/invitation/helpers.rb +6 -2
- data/lib/invitation/engine.rb +1 -1
- data/lib/invitation/version.rb +1 -1
- metadata +9 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7004e218adeff494276542ea6f2ba7827274af8668808d8621a239230e865527
|
4
|
+
data.tar.gz: d8f6097e1d66783c5c45cee8bf1df512fe323e4ccdcd72596f87253ff6f1af49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b38a8db6689536d0021cc41c712e0d0b5b468b30f9c8d49089fd8af3a75a6d5783b0fd7a9279cb2c277ea3d243ccf56ec60911d38ab1ee1806b7ebcda0de37d
|
7
|
+
data.tar.gz: 592918a6380483e92ed9a9119d03585d249bb2975168d8506b52b95cef3bb14b8933f67e21489211d6c344fd47da22f345c3085d7bae0348485b292909232778
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# Invitation Changelog
|
2
|
+
|
3
|
+
|
4
|
+
## [0.6.1] - October 1, 2019
|
5
|
+
|
6
|
+
### Fix: generator support for rails 6.0
|
7
|
+
- fixed migration_version in generators to support rails 5 and above
|
8
|
+
- Appraisal entry and gemfile for Rails 6.0.0
|
9
|
+
- bumped gemspec to include rails 6.0.0
|
10
|
+
- switched from factory_girl to factory_bot
|
11
|
+
|
12
|
+
[0.6.0]: https://github.com/tomichj/invitation/compare/0.6.0...0.6.1
|
13
|
+
|
14
|
+
|
15
|
+
## [0.6.0] - May 1, 2019
|
16
|
+
|
17
|
+
### Feature: support for rails 6.0
|
18
|
+
- added Appraisal entry and gemfile for 6.0.0rc1
|
19
|
+
- bumped gemspec to include rails 6.0.0rc1
|
20
|
+
- bumped version
|
21
|
+
|
22
|
+
[0.6.0]: https://github.com/tomichj/invitation/compare/0.5.1...0.6.0
|
23
|
+
|
24
|
+
|
25
|
+
## [0.5.1] - June 7, 2018
|
26
|
+
|
27
|
+
### Feature: support for rails 5.2
|
28
|
+
- added Appraisal entry and gemfile for 5.2
|
29
|
+
- added rakefile tasks for build and release
|
30
|
+
- bumped gemspec to include rails 5.2
|
31
|
+
- bumped version
|
32
|
+
- added sqlite3.represent_boolean_as_integer = true to dummy app for specs
|
33
|
+
- specs now test for http status 201 instead of :success and :created,
|
34
|
+
:success was deprecated, switched to 201 for brevity and longevity of test
|
35
|
+
|
36
|
+
[0.5.1]: https://github.com/tomichj/invitation/compare/0.5.0...0.5.1
|
37
|
+
|
38
|
+
|
39
|
+
## [0.5.0] - March 12, 2018
|
40
|
+
|
41
|
+
### API change
|
42
|
+
- `InviteForm` extracted from invites_controller.rb, added at `app/forms/invitation/invite_form.rb`
|
43
|
+
- `controllers_generator.rb` now has three targets: `create_controllers`, `create_mailers`, and `create_forms`
|
44
|
+
- deleted empty `lib/tasks/invitation_tasks.rake`
|
45
|
+
|
46
|
+
[0.5.0]: https://github.com/tomichj/invitation/compare/0.4.5...0.5.0
|
47
|
+
|
48
|
+
|
49
|
+
## [0.4.5] - March 9, 2018
|
50
|
+
|
51
|
+
### Bugfix:
|
52
|
+
- migration versioned for Rails >= 5
|
53
|
+
|
54
|
+
[0.4.5]: https://github.com/tomichj/invitation/compare/0.4.4...0.4.5
|
55
|
+
|
56
|
+
|
57
|
+
## [0.4.4] - September 30, 2017
|
58
|
+
- recipient association optional for Rails >= 5
|
59
|
+
|
60
|
+
[0.4.4]: https://github.com/tomichj/invitation/compare/0.4.3...0.4.4
|
61
|
+
|
62
|
+
|
63
|
+
## [0.4.3] - July 1, 2017
|
64
|
+
|
65
|
+
### API change
|
66
|
+
- configuration.user_model now accepts the user class (with a warning), or the user class name (a String)
|
67
|
+
|
68
|
+
[0.4.3]: https://github.com/tomichj/invitation/compare/0.4.2...0.4.3
|
69
|
+
|
70
|
+
|
71
|
+
## [0.4.2] - July 1, 2017
|
72
|
+
|
73
|
+
### API change
|
74
|
+
- accept a string for configuration.user_model and constantize it
|
75
|
+
|
76
|
+
[0.4.2]: https://github.com/tomichj/invitation/compare/0.4.1...0.4.2
|
77
|
+
|
78
|
+
|
79
|
+
## [0.4.1] - April 26, 2017
|
80
|
+
|
81
|
+
### Bugfix:
|
82
|
+
- added case_insensitive_email to template used by install generator
|
83
|
+
|
84
|
+
[0.4.1]: https://github.com/tomichj/invitation/compare/0.4...0.4.1
|
85
|
+
|
86
|
+
|
87
|
+
## [0.4] - April 26, 2017
|
88
|
+
|
89
|
+
### Feature:
|
90
|
+
- added case_sensitive_email configuration option.
|
91
|
+
|
92
|
+
[0.4]: https://github.com/tomichj/invitation/compare/0.3...0.4
|
93
|
+
|
94
|
+
|
95
|
+
## [0.3] - March 26, 2017
|
96
|
+
|
97
|
+
### Feature:
|
98
|
+
- Added support for Rails 5.1
|
99
|
+
|
100
|
+
[0.3]: https://github.com/tomichj/invitation/compare/0.2...0.3
|
101
|
+
|
102
|
+
|
103
|
+
## [0.2] - October 17, 2016
|
104
|
+
|
105
|
+
### Feature:
|
106
|
+
- adding pt-BR locale file and fixing an init bug.
|
107
|
+
|
108
|
+
[0.2]: https://github.com/tomichj/invitation/compare/0.1.1...0.2
|
109
|
+
|
110
|
+
|
111
|
+
## [0.1.1] - April 21, 2016
|
112
|
+
|
113
|
+
### Internal changes:
|
114
|
+
- invites controller now users a Form object, form accepts :email or :emails, builds one invite per email address.
|
115
|
+
|
116
|
+
[0.1.1]: https://github.com/tomichj/invitation/compare/0.1.0...0.1.1
|
117
|
+
|
118
|
+
|
119
|
+
## [0.1.0] - April 18, 2016
|
120
|
+
|
121
|
+
* `invites#create` supports :email or emails:[] in request, via html or json.
|
122
|
+
* `invites#create` error message reports emails it failed to invite
|
123
|
+
* `invites#create` invite_issued or invite_error messages now 'count' sensitive, e.g. "Invitation issued" vs "Invitations issued"
|
124
|
+
* removed after_invite_url from config, after invite user is redirected to invitable's show action
|
125
|
+
* added config.routes, set to true by default.
|
126
|
+
* fixed invitation view generator packaging
|
127
|
+
* significantly more tests
|
128
|
+
|
129
|
+
[0.1.0]: https://github.com/tomichj/invitation/compare/0.0.2...0.1.0
|
130
|
+
|
131
|
+
|
132
|
+
## [0.0.2] - April 11, 2016
|
133
|
+
|
134
|
+
* invites#create supports html or json. Redirects to invitable with html, returns invite (minus token) as json.
|
135
|
+
* gemspec dependencies cleaned up
|
136
|
+
* documentation updated
|
137
|
+
|
138
|
+
[0.0.2]: https://github.com/tomichj/invitation/compare/0.0.1...0.0.2
|
139
|
+
|
140
|
+
|
141
|
+
## 0.0.1 - April 9, 2016
|
142
|
+
|
143
|
+
Initial release.
|
144
|
+
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
I love pull requests. I'm trying to keep it as easy as possible to contribute changes. There
|
4
|
+
are just a couple of guidelines to follow to help me stay on top of things.
|
5
|
+
|
6
|
+
|
7
|
+
## Let's talk
|
8
|
+
|
9
|
+
Whether you're fixing a bug or adding a feature, feel free to talk to me first on
|
10
|
+
[twitter](https://twitter.com/JustinTomich). We can make sure the change isn't already
|
11
|
+
underway somewhere else.
|
12
|
+
|
13
|
+
|
14
|
+
## Getting started
|
15
|
+
|
16
|
+
* Make sure you have a [GitHub account](https://github.com/signup/free)
|
17
|
+
* Open a [New Issue](https://github.com/tomichj/invitation/issues) on github for your change,
|
18
|
+
assuming one does not already exist. If one already exists, join the conversation.
|
19
|
+
* Fork the repository on GitHub.
|
20
|
+
|
21
|
+
## Setup
|
22
|
+
|
23
|
+
Clone the repo:
|
24
|
+
|
25
|
+
`git clone https://github.com/<your-username>/invitation`
|
26
|
+
|
27
|
+
CD into your clone and run bundler install:
|
28
|
+
|
29
|
+
`cd invitation && bundle install`
|
30
|
+
|
31
|
+
Make sure the tests pass:
|
32
|
+
|
33
|
+
`rake`
|
34
|
+
|
35
|
+
Make your change. Add tests for your change. Make sure the tests pass:
|
36
|
+
|
37
|
+
`rake`
|
38
|
+
|
39
|
+
I use `rubocop` to maintain ruby coding style. Install and run it like so:
|
40
|
+
|
41
|
+
```sh
|
42
|
+
gem install rubocop
|
43
|
+
rubocop
|
44
|
+
```
|
45
|
+
|
46
|
+
Once you resolve any issues rubocop finds, you're ready to go. Push your fork and
|
47
|
+
[submit a pull request](https://github.com/tomichj/invitation/compare/).
|
48
|
+
|
49
|
+
The ball is now in my court. I'll try to comment on your pull request within a couple of business days
|
50
|
+
(hopefully the same day).
|
51
|
+
|
52
|
+
Things you can do to increase the speed of acceptance:
|
53
|
+
|
54
|
+
* talk to me ahead of time
|
55
|
+
* write tests
|
56
|
+
* follow the [ruby style guide](https://github.com/bbatsov/ruby-style-guide)
|
57
|
+
* write a good [commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
58
|
+
|
59
|
+
Thanks very much!
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Justin Tomich
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,378 @@
|
|
1
|
+
# Invitation
|
2
|
+
|
3
|
+
A Rails gem to issue scoped invitations.
|
4
|
+
|
5
|
+
Please see the [CHANGELOG] for information on the latest changes.
|
6
|
+
|
7
|
+
Please use [GitHub Issues] to report bugs. You can contact me directly on twitter at
|
8
|
+
[@JustinTomich](https://twitter.com/justintomich).
|
9
|
+
|
10
|
+
[](https://badge.fury.io/rb/invitation)  
|
11
|
+
|
12
|
+
|
13
|
+
## Overview
|
14
|
+
|
15
|
+
Allow users to invite others to join an organization or resource. Plenty of gems can issue a 'system-wide' invitation,
|
16
|
+
but few offer 'scoped' invitations, giving an invited user access to a particular invitable organization or resource.
|
17
|
+
|
18
|
+
Invitations are issued via email. You can invite users new to join the system while giving them permissions to
|
19
|
+
a resource, or invite existing users by giving them access to a new resource.
|
20
|
+
|
21
|
+
* a user can invite someone to join an invitable by providing an email address to invite
|
22
|
+
* if the user already exists, that user is granted access to the invitable, and a notification email is sent
|
23
|
+
* if the user does not exist, sends an email with a link to sign up. When the new user signs up,
|
24
|
+
they are added to the invitable resource/organization.
|
25
|
+
* the invite grants the invited user access to ONLY the invitable organization they were invited to.
|
26
|
+
|
27
|
+
|
28
|
+
## Prerequisites
|
29
|
+
|
30
|
+
* An authentication system with a User model and current_user helper, e.g. https://github.com/tomichj/authenticate
|
31
|
+
* Your user model must include an :email attribute.
|
32
|
+
* Additional model classes that are resources or organizations you wish to invite users to join, usually with a
|
33
|
+
many-to-many relationship to your user model.
|
34
|
+
* You probably also want an authorization system to restrict who can issue invitations to particular resources
|
35
|
+
|
36
|
+
A example user-to-organization system you might be familiar with: Basecamp's concepts of accounts and
|
37
|
+
projects (invitables) and users.
|
38
|
+
|
39
|
+
|
40
|
+
## Install
|
41
|
+
|
42
|
+
To get started, add Invitation to your `Gemfile` and run `bundle install` to install it:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'invitation'
|
46
|
+
```
|
47
|
+
|
48
|
+
Then run the invitation install generator:
|
49
|
+
|
50
|
+
```sh
|
51
|
+
rails generate invitation:install
|
52
|
+
```
|
53
|
+
|
54
|
+
If your user model is not User, you can optionally specify one: `rails generate invitation:install --model Profile`.
|
55
|
+
|
56
|
+
The install generator does the following:
|
57
|
+
|
58
|
+
* Add an initializer at `config/initializers/invitation.rb`, see [Configure](#configure) below.
|
59
|
+
* Insert `include Invitation::User` into your `User` model.
|
60
|
+
* Create a migration for the Invite class.
|
61
|
+
|
62
|
+
|
63
|
+
Then run the migration that Invitation just generated.
|
64
|
+
|
65
|
+
```sh
|
66
|
+
rake db:migrate
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
## Configure
|
71
|
+
|
72
|
+
Override any of these defaults in your application `config/initializers/invitation.rb`.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Invitation.configure do |config|
|
76
|
+
config.user_model = '::User'
|
77
|
+
config.user_registration_url = ->(params) { Rails.application.routes.url_helpers.sign_up_url(params) }
|
78
|
+
config.mailer_sender = 'reply@example.com'
|
79
|
+
config.routes = true
|
80
|
+
config.case_sensitive_email = true
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
Configuration parameters are described in detail here: [configuration]
|
85
|
+
|
86
|
+
|
87
|
+
### Invitable
|
88
|
+
|
89
|
+
You'll need to configure one or more model classes as `invitables`. Invitables are resources or organizations that
|
90
|
+
can be joined with an invite.
|
91
|
+
|
92
|
+
An `invitable` must have some sort of name for Invitation to use in views and mailers. An invitable needs to
|
93
|
+
call a class method, `invitable`, with one of the following options:
|
94
|
+
* `named: "String"`
|
95
|
+
* `named_by: :some_method_name`.
|
96
|
+
|
97
|
+
Example: a Company model that users can be invited to join. The companies are identified in invitation emails by
|
98
|
+
their `name` attribute:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
class Company < ActiveRecord::Base
|
102
|
+
invitable named_by: :name
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
|
107
|
+
### User Registration Controller
|
108
|
+
|
109
|
+
Your user registration controller must `include Invitation::UserRegistration`. You'll want to invoke `set_invite_token`
|
110
|
+
before you execute your `new` action, and `process_invite_token` after your `create` action.
|
111
|
+
|
112
|
+
If you're using [Authenticate](https://github.com/tomichj/authenticate), for example:
|
113
|
+
```ruby
|
114
|
+
class UsersController < Authenticate::UsersController
|
115
|
+
include Invitation::UserRegistration
|
116
|
+
before_action :set_invite_token, only: [:new]
|
117
|
+
after_action :process_invite_token, only: [:create]
|
118
|
+
end
|
119
|
+
```
|
120
|
+
To pass the invite token on signup, add `invite_token` as a hidden field in your signup form.
|
121
|
+
|
122
|
+
## Usage
|
123
|
+
|
124
|
+
Invitation adds routes to create invitations (GET new_invite and POST invites). Once you've configured
|
125
|
+
Invitation and set up an invitable, add a link to new_invite, specifying the the invitable id and type in the link:
|
126
|
+
|
127
|
+
```erb
|
128
|
+
<%= link_to 'invite a friend',
|
129
|
+
new_invite_path(invite: { invitable_id: account.id, invitable_type: 'Account' } ) %>
|
130
|
+
```
|
131
|
+
|
132
|
+
Invitation includes a simple `invitations#new` view which accepts an email address for a user to invite.
|
133
|
+
|
134
|
+
When the form is submitted, [invites#create](app/controllers/invitation/invites_controller.rb) will create
|
135
|
+
an [invite](app/models/invite.rb) to track the invitation. An email is then sent:
|
136
|
+
|
137
|
+
* a new user is emailed a link to your user registration page as set in [configuration], with a secure
|
138
|
+
invitation link that will be used to 'claim' the invitation when the new user registers
|
139
|
+
|
140
|
+
* an existing user is emailed a notification to tell them that they've been added to the resource
|
141
|
+
|
142
|
+
|
143
|
+
### JSON Invitation
|
144
|
+
|
145
|
+
You can send a JSON request to [invites#create](app/controllers/invitation/invites_controller.rb).
|
146
|
+
|
147
|
+
* request:
|
148
|
+
```javascript
|
149
|
+
invite:
|
150
|
+
{
|
151
|
+
"email": String,
|
152
|
+
"invitable_id": Number,
|
153
|
+
"invitable_type": String
|
154
|
+
}
|
155
|
+
```
|
156
|
+
|
157
|
+
or, with an array of multiple `emails`:
|
158
|
+
|
159
|
+
```javascript
|
160
|
+
invite:
|
161
|
+
{
|
162
|
+
"emails": [String],
|
163
|
+
"invitable_id": Number,
|
164
|
+
"invitable_type": String
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
168
|
+
* response:
|
169
|
+
```javascript
|
170
|
+
{
|
171
|
+
"id": Number,
|
172
|
+
"email": String,
|
173
|
+
"sender_id": Number,
|
174
|
+
"recipient_id": Number (optional),
|
175
|
+
"invitable_id": Number,
|
176
|
+
"invitable_type": String,
|
177
|
+
}
|
178
|
+
```
|
179
|
+
|
180
|
+
or, with multiple emails requested, an array of responses:
|
181
|
+
|
182
|
+
```javascript
|
183
|
+
[{
|
184
|
+
"id": Number,
|
185
|
+
"email": String,
|
186
|
+
"sender_id": Number,
|
187
|
+
"recipient_id": Number (optional),
|
188
|
+
"invitable_id": Number,
|
189
|
+
"invitable_type": String,
|
190
|
+
},
|
191
|
+
{
|
192
|
+
"id": Number,
|
193
|
+
"email": String,
|
194
|
+
"sender_id": Number,
|
195
|
+
"recipient_id": Number (optional),
|
196
|
+
"invitable_id": Number,
|
197
|
+
"invitable_type": String,
|
198
|
+
}]
|
199
|
+
```
|
200
|
+
|
201
|
+
## Security
|
202
|
+
|
203
|
+
Many systems require authorization to issue invitations to a resource. `Invitation` does not handle authorization,
|
204
|
+
but is intended to be a simple, easily extended framework upon which you can impose any required authorization scheme.
|
205
|
+
|
206
|
+
Most implementations will require extending the `InvitationsController`. [See below](#controllers) to read more
|
207
|
+
about extending InvitationController.
|
208
|
+
|
209
|
+
A common use case:
|
210
|
+
* every invitable resource has authorization requirements exposed via a method, we'll call it `can_invite?(user)`
|
211
|
+
* the current user must be authorized before issuing invitations
|
212
|
+
|
213
|
+
To implement: extend `InvitesController` and add a before_action to authorize access to the resource or resources. A
|
214
|
+
real implementation would probably do something more than just `raise 'unauthorized'`.
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
# app/controllers/invites_controller.rb
|
218
|
+
class InvitesController < Invitation::InvitesController
|
219
|
+
before_action :authorize
|
220
|
+
|
221
|
+
private
|
222
|
+
|
223
|
+
def authorize
|
224
|
+
invitable = load_invitable
|
225
|
+
invitable.can_invite?(current_user) or raise 'unauthorized'
|
226
|
+
end
|
227
|
+
|
228
|
+
def load_invitable
|
229
|
+
invite_params[:invitable_type].classify.constantize.find(invite_params[:invitable_id])
|
230
|
+
end
|
231
|
+
end
|
232
|
+
```
|
233
|
+
|
234
|
+
|
235
|
+
## Overriding Invitation
|
236
|
+
|
237
|
+
|
238
|
+
### Views
|
239
|
+
|
240
|
+
You can quickly get started with a rails application using the built-in views. See [app/views](/app/views) for
|
241
|
+
the default views. When you want to customize an Invitation view, create your own copy of it in your app.
|
242
|
+
|
243
|
+
You can use the Invitation view generator to copy the default views and translations
|
244
|
+
(see [translations](#translations) below) into your application:
|
245
|
+
|
246
|
+
```sh
|
247
|
+
$ rails generate invitation:views
|
248
|
+
```
|
249
|
+
|
250
|
+
|
251
|
+
### Routes
|
252
|
+
|
253
|
+
Invitation adds routes to your application. See [config/routes.rb](/config/routes.rb) for the default routes.
|
254
|
+
|
255
|
+
If you want to control and customize the routes, you can turn off the built-in routes in
|
256
|
+
the Invitation [configuration] with `config.routes = false` and dump a copy of the default routes into your
|
257
|
+
application for modification.
|
258
|
+
|
259
|
+
To turn off Invitation's built-in routes:
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
Invitation.configure do |config|
|
263
|
+
config.routes = false
|
264
|
+
end
|
265
|
+
```
|
266
|
+
|
267
|
+
You can run a generator to dump a copy of the default routes into your application for modification. The generator
|
268
|
+
will also switch off the routes by setting `config.routes = false` in your [configuration].
|
269
|
+
|
270
|
+
```sh
|
271
|
+
$ rails generate invitation:routes
|
272
|
+
```
|
273
|
+
|
274
|
+
|
275
|
+
### Controllers
|
276
|
+
|
277
|
+
You can customize the `invites_controller.rb` and the `invites_mailer.rb`. See [app/controllers](/app/controllers)
|
278
|
+
for the controller, and [app/mailers](/app/mailers) for the mailer.
|
279
|
+
|
280
|
+
To override `invites_controller.rb`, subclass the controller and update your routes to point to your implementation.
|
281
|
+
|
282
|
+
* subclass the controller:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
# app/controllers/invites_controller.rb
|
286
|
+
class InvitesController < Invitation::InvitesController
|
287
|
+
# render invite screen
|
288
|
+
def new
|
289
|
+
# ...
|
290
|
+
end
|
291
|
+
...
|
292
|
+
end
|
293
|
+
```
|
294
|
+
|
295
|
+
* update your routes to use your new controller.
|
296
|
+
|
297
|
+
Start by dumping a copy of Invitation's routes to your `config/routes.rb`:
|
298
|
+
|
299
|
+
```sh
|
300
|
+
$ rails generate invitation:routes
|
301
|
+
```
|
302
|
+
|
303
|
+
Now update `config/routes.rb`, changing the controller entry so it now points to your `invites` controller instead
|
304
|
+
of `invitation/invites`:
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
resources :invites, controller: 'invites', only: [:new, :create]
|
308
|
+
```
|
309
|
+
|
310
|
+
You can also use the Invitation controller generator to copy the default controller and mailer into
|
311
|
+
your application if you would prefer to more heavily modify the controller.
|
312
|
+
|
313
|
+
```sh
|
314
|
+
$ rails generate invitation:controllers
|
315
|
+
```
|
316
|
+
|
317
|
+
|
318
|
+
### Layout
|
319
|
+
|
320
|
+
Invitation uses your application's default layout. If you would like to change the layout Invitation uses when
|
321
|
+
rendering views, you can either deploy copies of the controllers and customize them, or you can specify
|
322
|
+
the layout in an initializer. This should be done in a to_prepare callback in `config/application.rb`
|
323
|
+
because it's executed once in production and before each request in development.
|
324
|
+
|
325
|
+
You can specify the layout per-controller:
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
config.to_prepare do
|
329
|
+
Invitation::InvitesController.layout 'my_invites_layout'
|
330
|
+
end
|
331
|
+
```
|
332
|
+
|
333
|
+
|
334
|
+
### Translations
|
335
|
+
|
336
|
+
All flash messages and email subject lines are stored in [i18n translations](http://guides.rubyonrails.org/i18n.html).
|
337
|
+
Override them like any other i18n translation.
|
338
|
+
|
339
|
+
See [config/locales/invitation.en.yml](/config/locales/invitation.en.yml) for the default messages.
|
340
|
+
|
341
|
+
|
342
|
+
## Thanks
|
343
|
+
|
344
|
+
This gem was inspired by and draws heavily from:
|
345
|
+
* https://gist.github.com/jlegosama/9026919
|
346
|
+
|
347
|
+
With additional inspiration from:
|
348
|
+
* https://github.com/scambra/devise_invitable
|
349
|
+
|
350
|
+
## Contributors
|
351
|
+
|
352
|
+
Many thanks to:
|
353
|
+
|
354
|
+
* [augustocbx](https://github.com/augustocbx) added pt-BR locale file and fixed an init bug
|
355
|
+
* [vincentwoo](https://github.com/vincentwoo/) raising the security bar, & bumping Invitation to rails 5.1
|
356
|
+
* [conarro](https://github.com/conarro) added case_sensitive_email configuration option
|
357
|
+
* [itkin](https://github.com/itkin) bugfix, stringified configuration.user_model
|
358
|
+
* [thesubr00t](https://github.com/thesubr00t) made recipient association optional for rails 5+
|
359
|
+
|
360
|
+
## Future changes
|
361
|
+
|
362
|
+
Possible future changes, some of which may be breaking:
|
363
|
+
|
364
|
+
* accepted flag, so we can scope invites by accepted vs not yet accepted
|
365
|
+
* expiration date - invites expire, scope expired by not expired
|
366
|
+
* move all view text to locale
|
367
|
+
* issue many invitations at once?
|
368
|
+
* dynamic user name lookup? requires JS, CSS
|
369
|
+
* add JS support to invites#create
|
370
|
+
|
371
|
+
## License
|
372
|
+
|
373
|
+
This project rocks and uses MIT-LICENSE.
|
374
|
+
|
375
|
+
|
376
|
+
[configuration]: lib/invitation/configuration.rb
|
377
|
+
[CHANGELOG]: CHANGELOG.md
|
378
|
+
[GitHub Issues]: https://github.com/tomichj/invitation/issues
|
@@ -69,9 +69,13 @@ module Invitation
|
|
69
69
|
end.join('::')
|
70
70
|
end
|
71
71
|
|
72
|
+
def rails5_and_up?
|
73
|
+
Rails::VERSION::MAJOR >= 5
|
74
|
+
end
|
75
|
+
|
72
76
|
def migration_version
|
73
|
-
if
|
74
|
-
"[#{
|
77
|
+
if rails5_and_up?
|
78
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
data/lib/invitation/engine.rb
CHANGED
data/lib/invitation/version.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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Tomich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
-
- - "<="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '6.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,23 +24,20 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '4.0'
|
30
|
-
- - "<="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '6.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: factory_bot
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
33
|
+
version: 4.11.1
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
version: 4.11.1
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rspec-rails
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +199,10 @@ executables: []
|
|
205
199
|
extensions: []
|
206
200
|
extra_rdoc_files: []
|
207
201
|
files:
|
202
|
+
- CHANGELOG.md
|
203
|
+
- CONTRIBUTING.md
|
204
|
+
- LICENSE
|
205
|
+
- README.md
|
208
206
|
- Rakefile
|
209
207
|
- app/controllers/invitation/invites_controller.rb
|
210
208
|
- app/forms/invitation/invite_form.rb
|