card-mod-account 0.11.0 → 0.11.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 446ac1cbd57b9473bffdf6fdb91303bc86cbcdcf584e2fafe48fc306da050580
4
- data.tar.gz: eecb9da6a9312154ec015ac20353061b8d2839a6c61d2dacabe9c2d3377603b9
3
+ metadata.gz: 8b9d1ba94c41d615071e2d65c85e31a7144e1238653b90a22630c4690a62eb0a
4
+ data.tar.gz: f992ea401a0f60f061bf8dfee1c6857f141819ce8c26dc25ebd9ce90950be4d3
5
5
  SHA512:
6
- metadata.gz: 9472b1ed791997464de8a57adad65d83b9021df74750f76edaab8fddfb51df493801f659c861a870ae29994e806add8add7e8aa8f07c73954b159f9e288ed050
7
- data.tar.gz: 8525e80cacd92f2d5c7ce960bbdda0be8fc63441fb3cb408080bbf03a0d9fe2c302da16ab60b117c923d5141bd1a62611e3bc48ad61cc677c6ac62729b1bce36
6
+ metadata.gz: 11b3de8aea618723fd95440d0957c8c206f016a7b3ebc63a9271c4955096eb02d4803303f6b461a26a8b8d8287470c82a680b7495d010b31f7379f9ee06c091d
7
+ data.tar.gz: 3b1c09772530fcd400a40c1104afe149adbaebd502780637cb478f9903e658993d03f8c12c01feed984c1ceb5f8cc2550f35e8d45acaa76b033f57d1a09bfa52
@@ -1,3 +1,8 @@
1
+ delegate :accounted, to: :account_card
2
+
3
+ def account_card
4
+ left
5
+ end
1
6
 
2
7
  # allow account owner to update account field content
3
8
  def ok_to_update
@@ -38,7 +38,11 @@ format :html do
38
38
  { path: { slot: { hide: %i[help_link bridge_link] } } }],
39
39
  ["Roles", :roles,
40
40
  { path: { view: :content_with_edit_button } }],
41
- ["Notifications", :follow]
41
+ ["Notifications", :follow],
42
+ ["API", :account,
43
+ { path: { view: :api_key,
44
+ items: { view: :content },
45
+ slot: { hide: %i[help_link bridge_link] } } }]
42
46
  ]
43
47
  end
44
48
 
data/set/all/account.rb CHANGED
@@ -39,6 +39,7 @@ def fetch_read_rules
39
39
 
40
40
  ([AnyoneID] + parties).each_with_object([]) do |party_id, rule_ids|
41
41
  next unless (cache = Card::Rule.read_rule_cache[party_id])
42
+
42
43
  rule_ids.concat cache
43
44
  end
44
45
  end
@@ -48,10 +49,16 @@ def clear_roles
48
49
  end
49
50
 
50
51
  def with_clear_roles
51
- a, b, c, d = @parties, @all_roles, @all_active_roles, @read_rules
52
+ a = @parties
53
+ b = @all_roles
54
+ c = @all_active_roles
55
+ d = @read_rules
52
56
  yield
53
57
  ensure
54
- @parties, @all_roles, @all_active_roles, @read_rules = a, b, c, d
58
+ @parties = a
59
+ @all_roles = b
60
+ @all_active_roles = c
61
+ @read_rules = d
55
62
  end
56
63
 
57
64
  def all_enabled_roles
@@ -63,15 +70,17 @@ def all_roles
63
70
  end
64
71
 
65
72
  def enabled_role_ids
66
- Auth.as_bot do
67
- # workaround for broken migrations
68
- return fetch_roles unless Card::Codename.exists? :enabled_roles
69
-
70
- enabled = enabled_roles_card
73
+ with_enabled_roles do |enabled|
71
74
  enabled.virtual? ? enabled.item_ids : fetch_roles
72
75
  end
73
76
  end
74
77
 
78
+ def with_enabled_roles
79
+ Auth.as_bot do
80
+ Card::Codename.exists?(:enabled_roles) ? yield(enabled_roles_card) : fetch_roles
81
+ end
82
+ end
83
+
75
84
  def enabled_roles_card
76
85
  fetch :enabled_roles, eager_cache: true, new: { type_id: SessionID }
77
86
  end
data/set/right/account.rb CHANGED
@@ -4,7 +4,6 @@ card_accessor :email
4
4
  card_accessor :password
5
5
  card_accessor :salt
6
6
  card_accessor :status
7
- card_accessor :api_key
8
7
 
9
8
  require_field :email
10
9
 
@@ -17,7 +16,7 @@ def accounted_id
17
16
  end
18
17
 
19
18
  def ok_to_read
20
- own_account? ? true : super
19
+ own_account? || super
21
20
  end
22
21
 
23
22
  # allow account owner to update account field content
@@ -43,16 +42,12 @@ def send_account_email email_template
43
42
  ecard.deliver self, to: email
44
43
  end
45
44
 
46
- def validate_api_key! api_key
47
- api_key_card.validate! api_key
48
- end
49
-
50
45
  def method_missing method, *args
51
- super unless args.empty? && (matches = method.match(/^(?<status>.*)\?$/))
46
+ return super unless args.empty? && (matches = method.match(/^(?<status>.*)\?$/))
52
47
 
53
48
  status == matches[:status]
54
49
  end
55
50
 
56
51
  def respond_to_missing? method, _include_private=false
57
- method.match?(/\?/) ? true : super
52
+ method.match?(/\?$/) ? true : super
58
53
  end
@@ -44,7 +44,7 @@ def activatable
44
44
  yield
45
45
  end
46
46
 
47
- # note: this only works in the context of an action.
47
+ # NOTE: this only works in the context of an action.
48
48
  # if run independently, it will not activate an account
49
49
  event :activate_account do
50
50
  add_subfield :status, content: "active"
@@ -95,5 +95,5 @@ end
95
95
 
96
96
  def reset_password_failure error_message
97
97
  Auth.as_bot { send_password_reset_email }
98
- errors.add :content, tr(:sorry_email_reset, error_msg: error_message)
98
+ errors.add :content, t(:account_sorry_email_reset, error_msg: error_message)
99
99
  end
data/set/right/email.rb CHANGED
@@ -8,7 +8,7 @@ event :validate_email, :validate, on: :save do
8
8
  self.content = content.strip
9
9
  return if content.match?(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
10
10
 
11
- errors.add :content, tr(:error_invalid_address)
11
+ errors.add :content, t(:account_error_invalid_address)
12
12
  end
13
13
 
14
14
  event :validate_unique_email, after: :validate_email, on: :save do
@@ -16,9 +16,9 @@ event :validate_unique_email, after: :validate_email, on: :save do
16
16
  Auth.as_bot do
17
17
  cql = { right_id: EmailID, eq: content, return: :id }
18
18
  cql[:not] = { id: id } if id
19
- cql_comment = tr(:search_email_duplicate, content: content)
19
+ cql_comment = t(:account_search_email_duplicate, content: content)
20
20
  if Card.search(cql, cql_comment).first
21
- errors.add :content, tr(:error_not_unique)
21
+ errors.add :content, t(:account_error_not_unique)
22
22
  end
23
23
  end
24
24
  end
@@ -26,6 +26,7 @@ end
26
26
 
27
27
  event :downcase_email, :prepare_to_validate, on: :save do
28
28
  return if !content || content == content.downcase
29
+
29
30
  self.content = content.downcase
30
31
  end
31
32
 
@@ -37,7 +38,7 @@ def ok_to_read
37
38
  if own_email? || Auth.always_ok?
38
39
  true
39
40
  else
40
- deny_because tr(:deny_email_restricted)
41
+ deny_because t(:account_deny_email_restricted)
41
42
  end
42
43
  end
43
44
 
@@ -5,7 +5,7 @@ def history?
5
5
  end
6
6
 
7
7
  def ok_to_read
8
- own_account? ? true : super
8
+ own_account? || super
9
9
  end
10
10
 
11
11
  event :encrypt_password, :store,
@@ -23,7 +23,7 @@ end
23
23
  event :validate_password, :validate, on: :save do
24
24
  return if content.length > 3
25
25
 
26
- errors.add :password, tr(:password_length)
26
+ errors.add :password, t(:account_password_length)
27
27
  end
28
28
 
29
29
  event :validate_password_present, :prepare_to_validate, on: :update do
@@ -31,7 +31,7 @@ event :validate_password_present, :prepare_to_validate, on: :update do
31
31
  end
32
32
 
33
33
  view :raw do
34
- tr :encrypted
34
+ t :account_encrypted
35
35
  end
36
36
 
37
37
  format :html do
@@ -46,6 +46,7 @@ format :html do
46
46
 
47
47
  def autocomplete?
48
48
  return "on" if @parent && @parent.card.name == "*signin+*account" # HACK
49
+
49
50
  "off"
50
51
  end
51
52
  end
data/set/right/roles.rb CHANGED
@@ -9,8 +9,8 @@ end
9
9
  def forbidden_roles
10
10
  # restore old roles for permission check
11
11
  with_old_role_permissions do |new_roles|
12
- new_roles.select do |card|
13
- !Card.fetch(card, "*members").ok? :update
12
+ new_roles.reject do |card|
13
+ Card.fetch(card, "*members").ok? :update
14
14
  end
15
15
  end
16
16
  end
data/set/right/salt.rb CHANGED
@@ -9,5 +9,5 @@ def history?
9
9
  end
10
10
 
11
11
  view :raw do
12
- tr :private_data
12
+ t :account_private_data
13
13
  end
data/set/right/status.rb CHANGED
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  def ok_to_update
13
13
  if own_account? && !Auth.always_ok?
14
- deny_because you_cant(tr(:deny_not_change_own_account))
14
+ deny_because you_cant(t(:account_deny_not_change_own_account))
15
15
  else
16
16
  super
17
17
  end
data/set/self/signin.rb CHANGED
@@ -30,8 +30,13 @@ end
30
30
  # triggered by clicking "Reset my Password", this sends out the verification password
31
31
  # and aborts (does not sign in)
32
32
  event :send_reset_password_token, before: :signin, on: :update, trigger: :required do
33
- email = subfield(:email)&.content
34
- send_reset_password_email_or_fail email
33
+ aborting do
34
+ blank_email? ? break : send_reset_password_email_or_fail
35
+ end
36
+ end
37
+
38
+ def email_from_subfield
39
+ @email_from_subfield ||= subfield(:email)&.content
35
40
  end
36
41
 
37
42
  def ok_to_read
@@ -42,10 +47,6 @@ def recaptcha_on?
42
47
  false
43
48
  end
44
49
 
45
- def i18n_signin key
46
- I18n.t key, scope: "mod.card-mod-account.set.self.signin"
47
- end
48
-
49
50
  def authenticate_or_abort email, pword
50
51
  abort_unless email, :email_missing
51
52
  abort_unless pword, :password_missing
@@ -64,53 +65,31 @@ def failed_signin email
64
65
  end
65
66
 
66
67
  def abort_unless value, error_key
67
- abort :failure, i18n_signin(error_key) unless value
68
+ abort :failure, t("account_#{error_key}") unless value
68
69
  end
69
70
 
70
71
  def signin_error_message account
71
- case
72
- when account.nil? then i18n_signin(:error_unknown_email)
73
- when !account.active? then i18n_signin(:error_not_active)
74
- else i18n_signin(:error_wrong_password)
75
- end
72
+ t "account_#{signin_error_key account}"
76
73
  end
77
74
 
78
75
  def error_on field, error_key
79
- errors.add field, i18n_signin(error_key)
76
+ errors.add field, t("account_#{error_key}")
80
77
  end
81
78
 
82
79
  def account_for email
83
80
  Auth.find_account_by_email email
84
81
  end
85
82
 
86
- def send_reset_password_email_or_fail email
87
- aborting do
88
- break errors.add :email, i18n_signin(:error_blank) if email.blank?
89
-
90
- if (account = Auth.find_account_by_email(email))&.active?
91
- Auth.as_bot { account.send_password_reset_email }
92
- elsif account
93
- errors.add :account, i18n_signin(:error_not_active)
94
- else
95
- errors.add :email, i18n_signin(:error_not_recognized)
96
- end
97
- end
98
- end
99
-
100
- def send_reset_password_email_or_fail email
101
- aborting do
102
- break if blank_email? email
103
-
104
- if (account = account_for email)&.active?
105
- send_reset_password_email account
106
- else
107
- reset_password_fail account
108
- end
83
+ def send_reset_password_email_or_fail
84
+ if (account = account_for email_from_subfield)&.active?
85
+ send_reset_password_email account
86
+ else
87
+ reset_password_fail account
109
88
  end
110
89
  end
111
90
 
112
- def blank_email? email
113
- return false if email.present?
91
+ def blank_email?
92
+ return false if email_from_subfield.present?
114
93
 
115
94
  error_on :email, :error_blank
116
95
  end
@@ -127,6 +106,16 @@ def reset_password_fail account
127
106
  end
128
107
  end
129
108
 
109
+ private
110
+
111
+ def signin_error_key account
112
+ case
113
+ when account.nil? then :error_unknown_email
114
+ when !account.active? then :error_not_active
115
+ else :error_wrong_password
116
+ end
117
+ end
118
+
130
119
  format :html do
131
120
  view :core, cache: :never do
132
121
  voo.edit_structure = [signin_field(:email), signin_field(:password)]
@@ -148,7 +137,7 @@ format :html do
148
137
 
149
138
  # FIXME: need a generic solution for this
150
139
  view :title do
151
- voo.title ||= I18n.t(:sign_in_title, scope: "mod.card-mod-account.set.self.signin")
140
+ voo.title ||= t(:account_sign_in_title)
152
141
  super()
153
142
  end
154
143
 
@@ -163,7 +152,7 @@ format :html do
163
152
 
164
153
  view :reset_password_success do
165
154
  # 'Check your email for a link to reset your password'
166
- frame { I18n.t(:check_email, scope: "mod.card-mod-account.set.self.signin") }
155
+ frame { t :account_check_email }
167
156
  end
168
157
 
169
158
  view :signin_buttons do
@@ -179,33 +168,31 @@ format :html do
179
168
  end
180
169
 
181
170
  def reset_password_voo
182
- voo.title ||= card.i18n_signin(:forgot_password)
171
+ voo.title ||= t :account_forgot_password
183
172
  voo.edit_structure = [signin_field(:email)]
184
173
  voo.hide :help
185
174
  end
186
175
 
187
176
  view :edit_buttons do
188
- text = I18n.t :reset_my_password, scope: "mod.card-mod-account.set.self.signin"
189
- button_tag text, situation: "primary", class: "_close-modal-on-success"
177
+ button_tag t(:account_reset_my_password),
178
+ situation: "primary", class: "_close-modal-on-success"
190
179
  end
191
180
 
192
181
  def signin_success
193
- "REDIRECT: #{Env.interrupted_action || '*previous'}"
182
+ { redirect: true, mark: (Env.interrupted_action || "*previous") }
194
183
  end
195
184
 
196
185
  def signin_button
197
- text = I18n.t :sign_in, scope: "mod.card-mod-account.set.self.signin"
198
- button_tag text, situation: "primary"
186
+ button_tag t(:account_sign_in), situation: "primary"
199
187
  end
200
188
 
201
189
  def signup_link
202
- text = I18n.t :or_sign_up, scope: "mod.card-mod-account.set.self.signin"
203
- subformat(Card[:account_links]).render! :sign_up, title: text
190
+ subformat(Card[:account_links]).render! :sign_up, title: t(:account_or_sign_up)
204
191
  end
205
192
 
206
193
  def reset_password_link
207
- text = I18n.t :reset_password, scope: "mod.card-mod-account.set.self.signin"
208
- link = link_to_view :edit, text, path: { slot: { hide: :bridge_link } }
194
+ link = link_to_view :edit, t(:account_reset_password),
195
+ path: { slot: { hide: :bridge_link } }
209
196
  # FIXME: inline styling
210
197
  raw("<div style='float:right'>#{link}</div>")
211
198
  end
@@ -4,7 +4,7 @@ format :html do
4
4
  end
5
5
 
6
6
  view :new do
7
- voo.title = invitation? ? tr(:invite) : tr(:sign_up)
7
+ voo.title = invitation? ? t(:account_invite) : t(:account_sign_up)
8
8
  super()
9
9
  end
10
10
 
@@ -20,6 +20,7 @@ format :html do
20
20
 
21
21
  def invite_button
22
22
  return unless invitation?
23
+
23
24
  button_tag "Send Invitation", situation: "primary"
24
25
  end
25
26
 
@@ -46,7 +47,7 @@ format :html do
46
47
  if card.account
47
48
  verification_lines
48
49
  else
49
- [tr(:missing_account)]
50
+ [t(:account_missing_account)]
50
51
  end
51
52
  end
52
53
 
@@ -57,12 +58,14 @@ format :html do
57
58
  def verification_sent_line
58
59
  account = card.account
59
60
  return unless account.email_card.ok?(:read)
61
+
60
62
  "A verification email has been sent to #{account.email}"
61
63
  end
62
64
 
63
65
  def verification_link_line
64
66
  links = verification_links
65
67
  return if links.empty?
68
+
66
69
  links.join " "
67
70
  end
68
71
 
@@ -81,6 +84,7 @@ format :html do
81
84
 
82
85
  def approval_link text, with_or_without
83
86
  return unless card.can_approve?
87
+
84
88
  link_to_card card, text,
85
89
  path: { action: :update,
86
90
  card: { trigger: "approve_#{with_or_without}_verification" } }
@@ -88,6 +92,7 @@ format :html do
88
92
 
89
93
  def deny_link
90
94
  return unless card.ok? :delete
95
+
91
96
  link_to_card card, "Deny and delete", path: { action: :delete }
92
97
  end
93
98
  end
data/set/type/user.rb CHANGED
@@ -35,7 +35,7 @@ format :html do
35
35
  def setup_hidden_fields
36
36
  hidden_tags(
37
37
  setup: true,
38
- success: "REDIRECT: #{path mark: ''}",
38
+ success: { redirect: true, mark: path(mark: "") },
39
39
  "card[type_id]" => Card.default_accounted_type_id
40
40
  )
41
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-account
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-12-24 00:00:00.000000000 Z
13
+ date: 2021-05-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,56 +18,56 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.101.0
21
+ version: 1.101.5
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.101.0
28
+ version: 1.101.5
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: card-mod-email
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.11.0
35
+ version: 0.11.5
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.11.0
42
+ version: 0.11.5
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: card-mod-permissions
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - '='
48
48
  - !ruby/object:Gem::Version
49
- version: 0.11.0
49
+ version: 0.11.5
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 0.11.0
56
+ version: 0.11.5
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: card-mod-list
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.11.0
63
+ version: 0.11.5
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.11.0
70
+ version: 0.11.5
71
71
  description: ''
72
72
  email:
73
73
  - info@decko.org
@@ -82,7 +82,6 @@ files:
82
82
  - set/right/account.rb
83
83
  - set/right/account/events.rb
84
84
  - set/right/account/views.rb
85
- - set/right/api_key.rb
86
85
  - set/right/email.rb
87
86
  - set/right/password.rb
88
87
  - set/right/roles.rb
@@ -97,10 +96,15 @@ files:
97
96
  - set/type/user.rb
98
97
  - set/type/user/setup_help.haml
99
98
  - set/type_plus_right/user/email.rb
100
- homepage: http://decko.org
99
+ homepage: https://decko.org
101
100
  licenses:
102
101
  - GPL-3.0
103
102
  metadata:
103
+ source_code_uri: https://github.com/decko-commons/decko
104
+ homepage_uri: https://decko.org
105
+ bug_tracker_uri: https://github.com/decko-commons/decko/issues
106
+ wiki_uri: https://decko.org
107
+ documentation_url: http://docs.decko.org/
104
108
  card-mod: account
105
109
  post_install_message:
106
110
  rdoc_options: []
@@ -117,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  - !ruby/object:Gem::Version
118
122
  version: '0'
119
123
  requirements: []
120
- rubygems_version: 3.0.3
124
+ rubygems_version: 3.1.4
121
125
  signing_key:
122
126
  specification_version: 4
123
127
  summary: Email-based account handling for decko cards
data/set/right/api_key.rb DELETED
@@ -1,48 +0,0 @@
1
- include_set Abstract::AccountField
2
-
3
- # DURATIONS = "second|minute|hour|day|week|month|year".freeze
4
-
5
- def history?
6
- false
7
- end
8
-
9
- view :raw do
10
- tr :private_data
11
- end
12
-
13
- def validate! api_key
14
- error =
15
- case
16
- when !real? then [:token_not_found, tr(:error_token_not_found)]
17
- # when expired? then [:token_expired, tr(:error_token_expired)]
18
- when content != api_key then [:incorrect_token, tr(:error_incorrect_token)]
19
- end
20
- errors.add(*error) if error
21
- error.nil?
22
- end
23
-
24
- # def expired?
25
- # !permanent? && updated_at <= term.ago
26
- # end
27
- #
28
- # def permanent?
29
- # term == "permanent"
30
- # end
31
-
32
- # def term
33
- # @term ||=
34
- # if expiration.present?
35
- # term_from_string expiration
36
- # else
37
- # Card.config.token_expiry
38
- # end
39
- # end
40
-
41
- # def term_from_string string
42
- # string.strip!
43
- # return "permanent" if string == "none"
44
- # re_match = /^(\d+)[\.\s]*(#{DURATIONS})s?$/.match(string)
45
- # number, unit = re_match.captures if re_match
46
- # raise Card::Open::Error, tr(:exception_bad_expiration, example: '2 days') unless unit
47
- # number.to_i.send unit
48
- # end