punk 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +9 -0
- data/.github/workflows/test.yml +26 -1
- data/.rdoc_options +23 -0
- data/.rgignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +5 -6
- data/Gemfile.lock +16 -29
- data/README.md +1 -1
- data/VERSION +1 -1
- data/app/migrations/001_lets_punk.rb +3 -0
- data/app/routes/hello.rb +4 -0
- data/env/.gitignore +3 -0
- data/env/spec/test.sh +3 -0
- data/lib/punk/actions/.keep +0 -0
- data/lib/punk/actions/groups/list.rb +24 -0
- data/lib/punk/actions/sessions/clear.rb +21 -0
- data/lib/punk/actions/sessions/create.rb +64 -0
- data/lib/punk/actions/sessions/list.rb +18 -0
- data/lib/punk/actions/sessions/verify.rb +24 -0
- data/lib/punk/actions/tenants/list.rb +18 -0
- data/lib/punk/actions/users/list_group.rb +18 -0
- data/lib/punk/actions/users/list_tenant.rb +18 -0
- data/lib/punk/actions/users/show.rb +18 -0
- data/lib/punk/commands/list.rb +12 -6
- data/lib/punk/config/defaults.json +3 -0
- data/lib/punk/config/schema.json +3 -0
- data/lib/punk/core/app.rb +4 -6
- data/lib/punk/core/commander.rb +7 -4
- data/lib/punk/core/exec.rb +2 -0
- data/lib/punk/core/load.rb +0 -1
- data/lib/punk/framework/command.rb +5 -1
- data/lib/punk/framework/plugins/validation.rb +0 -14
- data/lib/punk/helpers/loggable.rb +1 -1
- data/lib/punk/migrations/001_punk.rb +103 -0
- data/lib/punk/models/.keep +0 -0
- data/lib/punk/models/group.rb +20 -0
- data/lib/punk/models/group_user_metadata.rb +17 -0
- data/lib/punk/models/identity.rb +29 -0
- data/lib/punk/models/session.rb +89 -0
- data/lib/punk/models/tenant.rb +19 -0
- data/lib/punk/models/tenant_user_metadata.rb +17 -0
- data/lib/punk/models/user.rb +31 -0
- data/lib/punk/routes/groups.rb +31 -0
- data/lib/punk/routes/plivo.rb +4 -0
- data/lib/punk/routes/sessions.rb +108 -0
- data/lib/punk/routes/swagger.rb +9 -0
- data/lib/punk/routes/tenants.rb +29 -0
- data/lib/punk/routes/users.rb +36 -0
- data/lib/punk/services/.keep +0 -0
- data/lib/punk/services/challenge_claim.rb +46 -0
- data/lib/punk/services/create_identities.rb +25 -0
- data/lib/punk/services/generate_swagger.rb +25 -0
- data/lib/punk/services/prove_claim.rb +29 -0
- data/lib/punk/services/secret.rb +9 -0
- data/lib/punk/templates/groups/list.jbuilder +7 -0
- data/lib/punk/templates/plivo.slim +16 -0
- data/lib/punk/templates/sessions/list.jbuilder +6 -0
- data/lib/punk/templates/sessions/pending.jbuilder +4 -0
- data/lib/punk/templates/tenants/list.jbuilder +7 -0
- data/lib/punk/templates/tenants/list.slim +8 -0
- data/lib/punk/templates/users/list.jbuilder +7 -0
- data/lib/punk/templates/users/list.rcsv +4 -0
- data/lib/punk/templates/users/show.jbuilder +5 -0
- data/lib/punk/views/groups/list.rb +22 -0
- data/lib/punk/views/plivo_store.rb +15 -0
- data/lib/punk/views/sessions/list.rb +22 -0
- data/lib/punk/views/sessions/pending.rb +28 -0
- data/lib/punk/views/tenants/list.rb +22 -0
- data/lib/punk/views/users/list.rb +22 -0
- data/lib/punk/views/users/show.rb +22 -0
- data/lib/punk/workers/.keep +0 -0
- data/lib/punk/workers/expire_sessions.rb +9 -0
- data/lib/punk/workers/geocode_session_worker.rb +48 -0
- data/lib/punk/workers/identify_session_worker.rb +45 -0
- data/lib/punk/workers/secret.rb +18 -0
- data/lib/punk/workers/send_email_worker.rb +51 -0
- data/lib/punk/workers/send_sms_worker.rb +40 -0
- data/punk.gemspec +140 -14
- data/schema.psql +345 -0
- data/spec/actions/groups/punk/list_groups_action_spec.rb +36 -0
- data/spec/actions/sessions/punk/clear_session_action_spec.rb +29 -0
- data/spec/actions/sessions/punk/create_session_action_spec.rb +33 -0
- data/spec/actions/sessions/punk/list_sessions_action_spec.rb +26 -0
- data/spec/actions/sessions/punk/verify_session_action_spec.rb +59 -0
- data/spec/actions/tenants/punk/list_tenants_action_spec.rb +25 -0
- data/spec/actions/users/punk/list_group_users_action_spec.rb +26 -0
- data/spec/actions/users/punk/list_tenant_users_action_spec.rb +26 -0
- data/spec/factories/group.rb +12 -0
- data/spec/factories/group_user_metadata.rb +10 -0
- data/spec/factories/identity.rb +19 -0
- data/spec/factories/session.rb +12 -0
- data/spec/factories/tenant.rb +10 -0
- data/spec/factories/tenant_user_metadata.rb +10 -0
- data/spec/factories/user.rb +12 -0
- data/spec/lib/commands/auth_spec.rb +11 -0
- data/spec/lib/commands/generate_spec.rb +7 -0
- data/spec/lib/commands/http_spec.rb +23 -0
- data/spec/lib/commands/list_spec.rb +7 -0
- data/spec/lib/commands/swagger_spec.rb +7 -0
- data/spec/lib/engine/punk_env_spec.rb +13 -0
- data/spec/lib/engine/punk_exec_spec.rb +9 -0
- data/spec/lib/engine/punk_init_spec.rb +9 -0
- data/spec/lib/engine/punk_store_spec.rb +10 -0
- data/spec/lib/punk.env +7 -0
- data/spec/models/punk/group_spec.rb +50 -0
- data/spec/models/punk/group_user_metadata_spec.rb +61 -0
- data/spec/models/punk/identity_spec.rb +61 -0
- data/spec/models/punk/session_spec.rb +156 -0
- data/spec/models/punk/tenant_spec.rb +51 -0
- data/spec/models/punk/tenant_user_metadata_spec.rb +61 -0
- data/spec/models/punk/user_spec.rb +115 -0
- data/spec/routes/groups/get_groups_spec.rb +33 -0
- data/spec/routes/plivo/get_plivo_spec.rb +11 -0
- data/spec/routes/sessions/delete_session_spec.rb +11 -0
- data/spec/routes/sessions/get_sessions_spec.rb +30 -0
- data/spec/routes/sessions/patch_session_spec.rb +11 -0
- data/spec/routes/sessions/post_session_spec.rb +11 -0
- data/spec/routes/swagger/get_swagger_spec.rb +12 -0
- data/spec/routes/tenants/get_tenants_spec.rb +31 -0
- data/spec/routes/users/get_users_spec.rb +60 -0
- data/spec/services/punk/challenge_claim_service_spec.rb +7 -0
- data/spec/services/punk/create_identities_service_spec.rb +14 -0
- data/spec/services/punk/generate_swagger_service_spec.rb +7 -0
- data/spec/services/punk/prove_claim_service_spec.rb +7 -0
- data/spec/services/punk/secret_service_spec.rb +7 -0
- data/spec/spec_helper.rb +122 -0
- data/spec/vcr_cassettes/PUNK_GeocodeSessionWorker/updates_the_session_data.yml +57 -0
- data/spec/vcr_cassettes/PUNK_IdentifySessionWorker/updates_the_session_data.yml +112 -0
- data/spec/views/punk/plivo_store_spec.rb +7 -0
- data/spec/views/sessions/punk/list_sessions_view_spec.rb +7 -0
- data/spec/views/sessions/punk/pending_session_view_spec.rb +7 -0
- data/spec/views/tenants/punk/list_tenants_view_spec.rb +7 -0
- data/spec/views/users/punk/list_groups_view_spec.rb +7 -0
- data/spec/views/users/punk/list_users_view_spec.rb +7 -0
- data/spec/workers/punk/expire_sessions_worker_spec.rb +31 -0
- data/spec/workers/punk/geocode_session_worker_spec.rb +14 -0
- data/spec/workers/punk/identify_session_worker_spec.rb +15 -0
- data/spec/workers/punk/secret_worker_spec.rb +20 -0
- data/spec/workers/punk/send_email_worker_spec.rb +46 -0
- data/spec/workers/punk/send_sms_worker_spec.rb +33 -0
- metadata +148 -11
- data/lib/punk/views/all.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7178f5eae926161a0706c9c64ef8e57228ccb5ef5104ebb353b1595085755d8f
|
4
|
+
data.tar.gz: 0ef6b97cbaeb614f08dc85e51ef97d3382c82dc277d61a438078abacdcdd53f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb1b9ee114d8696a90f7cfc47c6a6aae3d759a8121dfd4e0e3f5ec3756db57d77d99eb94aab1165f3c3c7101cec8ae2a8310c04ccbf4b03dca5e9f3fb1f11b05
|
7
|
+
data.tar.gz: c3aa57ef40815657a8fd029d4bd1d116dfc28db30287345149815635e824d27740a6909667345512f98150c593673f83b51877a4d7c8cbc063cc7cb6f95ca12f
|
data/.editorconfig
ADDED
data/.github/workflows/test.yml
CHANGED
@@ -7,6 +7,28 @@ jobs:
|
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
env:
|
9
9
|
PUNK_ENV: test
|
10
|
+
COVERALLS_REPO_TOKEN: "${{secrets.COVERALLS_REPO_TOKEN}}"
|
11
|
+
IPSTACK_ACCESS_KEY: "${{secrets.IPSTACK_ACCESS_KEY}}"
|
12
|
+
USERSTACK_API_KEY: "${{secrets.USERSTACK_API_KEY}}"
|
13
|
+
DATABASE_URL: "postgres://postgres:postgres@localhost/punk_test"
|
14
|
+
|
15
|
+
services:
|
16
|
+
postgres:
|
17
|
+
image: postgres
|
18
|
+
env:
|
19
|
+
POSTGRES_PASSWORD: postgres
|
20
|
+
options: >-
|
21
|
+
--health-cmd pg_isready
|
22
|
+
--health-interval 10s
|
23
|
+
--health-timeout 5s
|
24
|
+
--health-retries 5
|
25
|
+
ports:
|
26
|
+
- 5432:5432
|
27
|
+
memcached:
|
28
|
+
image: memcached
|
29
|
+
ports:
|
30
|
+
- 11211:11211
|
31
|
+
options: --health-cmd "timeout 5 bash -c 'cat < /dev/null > /dev/udp/127.0.0.1/11211'" --health-interval 10s --health-timeout 5s --health-retries 5
|
10
32
|
steps:
|
11
33
|
- uses: actions/checkout@v2
|
12
34
|
- name: Set up Ruby
|
@@ -17,4 +39,7 @@ jobs:
|
|
17
39
|
- name: Lint files
|
18
40
|
run: bundle exec rubocop
|
19
41
|
- name: Run specs
|
20
|
-
run:
|
42
|
+
run: |
|
43
|
+
bundle exec ruby ./bin/punk db create
|
44
|
+
bundle exec ruby ./bin/punk db migrate
|
45
|
+
bundle exec rspec
|
data/.rdoc_options
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
--- !ruby/object:RDoc::Options
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: []
|
4
|
+
rdoc_include:
|
5
|
+
- "."
|
6
|
+
- "/Users/jason/dev/rocket_engine"
|
7
|
+
charset: UTF-8
|
8
|
+
exclude:
|
9
|
+
hyperlink_all: false
|
10
|
+
line_numbers: false
|
11
|
+
locale:
|
12
|
+
locale_dir: locale
|
13
|
+
locale_name:
|
14
|
+
main_page:
|
15
|
+
markup: markdown
|
16
|
+
output_decoration: true
|
17
|
+
page_dir:
|
18
|
+
show_hash: false
|
19
|
+
tab_width: 8
|
20
|
+
template_stylesheets: []
|
21
|
+
title:
|
22
|
+
visibility: :protected
|
23
|
+
webcvs:
|
data/.rgignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.lock
|
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -47,7 +47,7 @@ gem 'aasm', '~> 5.1'
|
|
47
47
|
|
48
48
|
# Authentication
|
49
49
|
gem 'http-accept', '~> 2.1'
|
50
|
-
gem '
|
50
|
+
gem 'ipstack', '~> 0.1'
|
51
51
|
gem 'rbnacl', '~> 7.1'
|
52
52
|
gem 'userstack', '~> 0.1'
|
53
53
|
|
@@ -70,7 +70,7 @@ gem 'slim', '~> 4.1'
|
|
70
70
|
|
71
71
|
# JSON Rendering
|
72
72
|
gem 'jbuilder', '~> 2.10'
|
73
|
-
gem 'oj', '~> 3.
|
73
|
+
gem 'oj', '~> 3.11'
|
74
74
|
gem 'tilt-jbuilder', '~> 0.7'
|
75
75
|
|
76
76
|
# Documentation Generation
|
@@ -81,7 +81,8 @@ gem 'swagger_yard', '~> 1.0'
|
|
81
81
|
gem 'activesupport', '~> 6.1'
|
82
82
|
|
83
83
|
# Monitoring
|
84
|
-
gem 'sentry-
|
84
|
+
gem 'sentry-ruby', '~> 4.1'
|
85
|
+
gem 'sentry-sidekiq', '~> 4.1'
|
85
86
|
gem 'skylight', '~> 4.3'
|
86
87
|
|
87
88
|
# Phone Numbers
|
@@ -96,18 +97,16 @@ end
|
|
96
97
|
|
97
98
|
# Testing
|
98
99
|
group :test do
|
99
|
-
gem 'capybara', '~> 3.34'
|
100
100
|
gem 'coveralls', '~> 0.8'
|
101
101
|
gem 'factory_bot', '~> 6.1'
|
102
102
|
gem 'faker', '~> 2.15'
|
103
103
|
gem 'rack-test', '~> 1.1'
|
104
104
|
gem 'rspec', '~> 3.10'
|
105
105
|
gem 'rspec-its', '~> 1.3'
|
106
|
-
gem 'rubocop', '~> 1.
|
106
|
+
gem 'rubocop', '~> 1.8'
|
107
107
|
gem 'rubocop-rails', '~> 2.9'
|
108
108
|
gem 'rubocop-rspec', '~> 2.1'
|
109
109
|
gem 'rubocop-sequel', '~> 0.1'
|
110
|
-
gem 'selenium-webdriver', '~> 3.142'
|
111
110
|
gem 'timecop', '~> 0.9'
|
112
111
|
gem 'vcr', '~> 6.0'
|
113
112
|
gem 'webmock', '~> 3.11'
|
data/Gemfile.lock
CHANGED
@@ -18,15 +18,6 @@ GEM
|
|
18
18
|
msgpack (~> 1.0)
|
19
19
|
builder (3.2.4)
|
20
20
|
byebug (11.1.3)
|
21
|
-
capybara (3.34.0)
|
22
|
-
addressable
|
23
|
-
mini_mime (>= 0.1.3)
|
24
|
-
nokogiri (~> 1.8)
|
25
|
-
rack (>= 1.6.0)
|
26
|
-
rack-test (>= 0.6.3)
|
27
|
-
regexp_parser (~> 1.5)
|
28
|
-
xpath (~> 3.2)
|
29
|
-
childprocess (3.0.0)
|
30
21
|
chronic (0.10.2)
|
31
22
|
coderay (1.1.3)
|
32
23
|
commander (4.5.2)
|
@@ -62,7 +53,7 @@ GEM
|
|
62
53
|
faraday_middleware (1.0.0)
|
63
54
|
faraday (~> 1.0)
|
64
55
|
ffi (1.14.2)
|
65
|
-
fugit (1.4.
|
56
|
+
fugit (1.4.2)
|
66
57
|
et-orbi (~> 1.1, >= 1.1.8)
|
67
58
|
raabro (~> 1.4)
|
68
59
|
gemfile_updater (0.1.0)
|
@@ -83,6 +74,8 @@ GEM
|
|
83
74
|
domain_name (~> 0.5)
|
84
75
|
i18n (1.8.7)
|
85
76
|
concurrent-ruby (~> 1.0)
|
77
|
+
ipstack (0.1.3)
|
78
|
+
nokogiri (>= 1.8, < 2.0)
|
86
79
|
jbuilder (2.10.1)
|
87
80
|
activesupport (>= 5.0.0)
|
88
81
|
json (2.5.1)
|
@@ -105,12 +98,10 @@ GEM
|
|
105
98
|
addressable (~> 2.7)
|
106
99
|
mailgun-ruby (1.2.0)
|
107
100
|
rest-client (~> 2.0.2)
|
108
|
-
maxmind-db (1.1.1)
|
109
101
|
method_source (1.0.0)
|
110
102
|
mime-types (3.3.1)
|
111
103
|
mime-types-data (~> 3.2015)
|
112
104
|
mime-types-data (3.2020.1104)
|
113
|
-
mini_mime (1.0.2)
|
114
105
|
mini_portile2 (2.5.0)
|
115
106
|
minitest (5.14.3)
|
116
107
|
msgpack (1.3.3)
|
@@ -128,7 +119,7 @@ GEM
|
|
128
119
|
multi_json (~> 1.3)
|
129
120
|
multi_xml (~> 0.5)
|
130
121
|
rack (>= 1.2, < 3)
|
131
|
-
oj (3.
|
122
|
+
oj (3.11.0)
|
132
123
|
papertrail (0.11.0)
|
133
124
|
ansi (~> 1.5)
|
134
125
|
chronic (~> 0.10)
|
@@ -171,7 +162,7 @@ GEM
|
|
171
162
|
rchardet (1.8.0)
|
172
163
|
rdoc (6.3.0)
|
173
164
|
redis (4.2.5)
|
174
|
-
regexp_parser (
|
165
|
+
regexp_parser (2.0.3)
|
175
166
|
rest-client (2.0.2)
|
176
167
|
http-cookie (>= 1.0.2, < 2.0)
|
177
168
|
mime-types (>= 1.16, < 4.0)
|
@@ -197,7 +188,7 @@ GEM
|
|
197
188
|
diff-lcs (>= 1.2.0, < 2.0)
|
198
189
|
rspec-support (~> 3.10.0)
|
199
190
|
rspec-support (3.10.1)
|
200
|
-
rubocop (1.8.
|
191
|
+
rubocop (1.8.1)
|
201
192
|
parallel (~> 1.10)
|
202
193
|
parser (>= 3.0.0.0)
|
203
194
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -218,15 +209,14 @@ GEM
|
|
218
209
|
rubocop-sequel (0.1.0)
|
219
210
|
rubocop (~> 1.0)
|
220
211
|
ruby-progressbar (1.11.0)
|
221
|
-
rubyzip (2.3.0)
|
222
|
-
selenium-webdriver (3.142.7)
|
223
|
-
childprocess (>= 0.5, < 4.0)
|
224
|
-
rubyzip (>= 1.2.2)
|
225
212
|
semantic_logger (4.7.4)
|
226
213
|
concurrent-ruby (~> 1.0)
|
227
214
|
semver2 (3.4.2)
|
228
|
-
sentry-
|
215
|
+
sentry-ruby (4.1.3)
|
216
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
229
217
|
faraday (>= 1.0)
|
218
|
+
sentry-sidekiq (4.1.2)
|
219
|
+
sentry-ruby (~> 4.1.2)
|
230
220
|
sequel (5.40.0)
|
231
221
|
sequel_pg (1.14.0)
|
232
222
|
pg (>= 0.18.0, != 1.2.0)
|
@@ -264,7 +254,7 @@ GEM
|
|
264
254
|
jbuilder
|
265
255
|
tilt (>= 1.3.0, < 3)
|
266
256
|
timecop (0.9.2)
|
267
|
-
tins (1.
|
257
|
+
tins (1.28.0)
|
268
258
|
sync
|
269
259
|
tzinfo (2.0.4)
|
270
260
|
concurrent-ruby (~> 1.0)
|
@@ -279,8 +269,6 @@ GEM
|
|
279
269
|
crack (>= 0.3.2)
|
280
270
|
hashdiff (>= 0.4.0, < 2.0.0)
|
281
271
|
wisper (2.0.1)
|
282
|
-
xpath (3.2.0)
|
283
|
-
nokogiri (~> 1.8)
|
284
272
|
yard (0.9.26)
|
285
273
|
zeitwerk (2.4.2)
|
286
274
|
|
@@ -294,7 +282,6 @@ DEPENDENCIES
|
|
294
282
|
bootsnap (~> 1.5)
|
295
283
|
bundler (~> 1.17)
|
296
284
|
byebug (~> 11.1)
|
297
|
-
capybara (~> 3.34)
|
298
285
|
commander (~> 4.5)
|
299
286
|
coveralls (~> 0.8)
|
300
287
|
dalli (~> 2.7)
|
@@ -305,12 +292,12 @@ DEPENDENCIES
|
|
305
292
|
faker (~> 2.15)
|
306
293
|
gemfile_updater (~> 0.1)
|
307
294
|
http-accept (~> 2.1)
|
295
|
+
ipstack (~> 0.1)
|
308
296
|
jbuilder (~> 2.10)
|
309
297
|
juwelier (~> 2.4)
|
310
298
|
launchy (~> 2.5)
|
311
299
|
mailgun-ruby (~> 1.2)
|
312
|
-
|
313
|
-
oj (~> 3.10)
|
300
|
+
oj (~> 3.11)
|
314
301
|
papertrail (~> 0.11)
|
315
302
|
pg (~> 1.2)
|
316
303
|
phony (~> 2.18)
|
@@ -329,13 +316,13 @@ DEPENDENCIES
|
|
329
316
|
roda-route_list (~> 2.1)
|
330
317
|
rspec (~> 3.10)
|
331
318
|
rspec-its (~> 1.3)
|
332
|
-
rubocop (~> 1.
|
319
|
+
rubocop (~> 1.8)
|
333
320
|
rubocop-rails (~> 2.9)
|
334
321
|
rubocop-rspec (~> 2.1)
|
335
322
|
rubocop-sequel (~> 0.1)
|
336
|
-
selenium-webdriver (~> 3.142)
|
337
323
|
semantic_logger (~> 4.7)
|
338
|
-
sentry-
|
324
|
+
sentry-ruby (~> 4.1)
|
325
|
+
sentry-sidekiq (~> 4.1)
|
339
326
|
sequel (~> 5.40)
|
340
327
|
sequel_pg (~> 1.14)
|
341
328
|
sidekiq (~> 6.1)
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![test](https://github.com/kranzky/punk/workflows/test/badge.svg)](https://github.com/kranzky/punk/actions?query=workflow%3Atest)
|
2
|
-
[![
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/github/kranzky/punk/badge.svg?branch=main)](https://coveralls.io/github/kranzky/punk?branch=main)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/punk.svg)](https://badge.fury.io/rb/punk)
|
4
4
|
|
5
5
|
# Punk!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/app/routes/hello.rb
ADDED
data/env/.gitignore
ADDED
data/env/spec/test.sh
ADDED
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PUNK
|
4
|
+
class ListGroupsAction < Action
|
5
|
+
args :user, :tenant
|
6
|
+
|
7
|
+
def validate
|
8
|
+
validates_not_null :user
|
9
|
+
validates_not_empty :user
|
10
|
+
return if user.blank?
|
11
|
+
validates_not_null :tenant
|
12
|
+
validates_not_empty :tenant
|
13
|
+
return if tenant.blank?
|
14
|
+
validates_type User, :user
|
15
|
+
validates_type Tenant, :tenant
|
16
|
+
end
|
17
|
+
|
18
|
+
def process
|
19
|
+
# TODO: repository here
|
20
|
+
# an action takes arguments (that may be entities) and returns a view object
|
21
|
+
present ListGroupsView, groups: user.groups_dataset.where(tenant: tenant).all
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PUNK
|
4
|
+
class ClearSessionAction < Action
|
5
|
+
args :session
|
6
|
+
|
7
|
+
def validate
|
8
|
+
validates_not_null :session
|
9
|
+
validates_not_empty :session
|
10
|
+
return if session.blank?
|
11
|
+
validates_type Session, :session
|
12
|
+
validates_state :session, :active
|
13
|
+
validates_event :session, :clear
|
14
|
+
end
|
15
|
+
|
16
|
+
def process
|
17
|
+
session.clear!
|
18
|
+
present Info, message: "You have been logged out."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'phony'
|
5
|
+
|
6
|
+
module PUNK
|
7
|
+
class CreateSessionAction < Action
|
8
|
+
args :claim, :remote_addr, :user_agent
|
9
|
+
|
10
|
+
def validate
|
11
|
+
validates_not_null :claim
|
12
|
+
validates_not_empty :claim
|
13
|
+
validates_not_null :claim_type, message: "is not an email address or phone number"
|
14
|
+
validates_email :claim if claim_type == :email
|
15
|
+
validates_phone :claim if claim_type == :phone
|
16
|
+
validates_not_null :remote_addr
|
17
|
+
validates_not_empty :remote_addr
|
18
|
+
validates_not_null :user_agent
|
19
|
+
validates_not_empty :user_agent
|
20
|
+
end
|
21
|
+
|
22
|
+
def process
|
23
|
+
PUNK.db.transaction do
|
24
|
+
identity =
|
25
|
+
Identity.find_or_create(claim: _normalize_claim) do |i|
|
26
|
+
i.claim_type = claim_type
|
27
|
+
end
|
28
|
+
session = Session.create(identity: identity, remote_addr: remote_addr, user_agent: user_agent)
|
29
|
+
ChallengeClaimService.run(session: session)
|
30
|
+
IdentifySessionWorker.perform_async(session_id: session.id)
|
31
|
+
message =
|
32
|
+
case identity.claim_type
|
33
|
+
when :email
|
34
|
+
"We have sent a verification code to your email address. Please enter it to verify your identity."
|
35
|
+
when :phone
|
36
|
+
"We have sent a verification code to your phone number by SMS. Please enter it to verify your identity."
|
37
|
+
end
|
38
|
+
present PendingSessionView, session: session, message: message, status: 201
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def claim_type
|
43
|
+
@claim_type ||= _guess_claim_type
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def _guess_claim_type
|
49
|
+
return :email if URI::MailTo::EMAIL_REGEXP.match(claim)
|
50
|
+
return :phone if Phony.plausible?(claim)
|
51
|
+
end
|
52
|
+
|
53
|
+
def _normalize_claim
|
54
|
+
case claim_type
|
55
|
+
when :email
|
56
|
+
claim.downcase.strip
|
57
|
+
when :phone
|
58
|
+
phone = claim.strip
|
59
|
+
phone = "+1#{phone}" if phone !~ /^[+]/
|
60
|
+
"+#{Phony.normalize(phone)}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PUNK
|
4
|
+
class ListSessionsAction < Action
|
5
|
+
args :user
|
6
|
+
|
7
|
+
def validate
|
8
|
+
validates_not_null :user
|
9
|
+
validates_not_empty :user
|
10
|
+
return if user.blank?
|
11
|
+
validates_type User, :user
|
12
|
+
end
|
13
|
+
|
14
|
+
def process
|
15
|
+
present ListSessionsView, sessions: user.active_sessions.all
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|