openproject-token 2.1.0 → 2.2.0

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: d218d4572439ee41238271a09ad784c6a94be598e8028664d2d9ad3ac0a26115
4
- data.tar.gz: 02adcfc7070c95e4d972a59b6df4dc812631855fcc008e6ba2fcbf9fcb6f3a9f
3
+ metadata.gz: 674fb4bda421c9bc39debd39abf5ef0103070da6c27967334c2d237480aeb893
4
+ data.tar.gz: 0e9d87592b6479b00163c2ada64649b959924b8c845468419814599733fe6ab0
5
5
  SHA512:
6
- metadata.gz: 4698826acfa3110b50d0d8989148ed44025722a968f2f13d257573fe05550685480b7dacc5786ec6ee450b6704eba6b60ea70cce97e2e631bc19c0a4968c3908
7
- data.tar.gz: 29a1fdb2b2c20ec9f0af23769e31c2ac990f490932bda21314faa26387a9d617309da6a0d2591b02bb7f411a4784f7829d10007d77e30baff0e2183575558e7c
6
+ metadata.gz: 415fd95a605f1b34205253b24873a359cf4fb9546f6bc6a3ae7442746f46075f1521cd9195009ff9e045de9139908c42124b59c68294abeeedc7c96f18e223ea
7
+ data.tar.gz: a658f645da29350cb45f1ec144690a474ed316249eb0ef2f3364f97a1e1ee4bdcdd4c5472dd4f5dea85128aa4a4ccd63a84fbc2b5873ed3c4fb1bc37f415c0d8
@@ -1,5 +1,5 @@
1
1
  module OpenProject
2
2
  class Token
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
@@ -51,6 +51,7 @@ module OpenProject
51
51
  attr_reader :version
52
52
  attr_accessor :subscriber, :mail, :company, :domain
53
53
  attr_accessor :starts_at, :issued_at, :expires_at
54
+ attr_accessor :reprieve_days
54
55
  attr_accessor :notify_admins_at, :notify_users_at, :block_changes_at
55
56
  attr_accessor :restrictions
56
57
 
@@ -90,8 +91,29 @@ module OpenProject
90
91
  self.block_changes_at
91
92
  end
92
93
 
93
- def expired?
94
- will_expire? && Date.today >= self.expires_at
94
+ ##
95
+ # Indicates whether or not the token has expired.
96
+ #
97
+ # This does include a reprieve (grace period) if configured.
98
+ # I.e. this will return false even if `expires_at` has passed
99
+ # if `reprieve_days` is configured, as long as the current date
100
+ # is still within those days after the actual expiration.
101
+ #
102
+ # @param reprieve [Boolean] Allow for reprieve (default true)
103
+ def expired?(reprieve: true)
104
+ offset = reprieve ? reprieve_days.to_i : 0
105
+
106
+ will_expire? && Date.today >= self.expires_at.next_day(offset)
107
+ end
108
+
109
+ ##
110
+ # Returns the number of days of reprieve left after the token has expired.
111
+ #
112
+ # @return Returns `nil` if the token hasn't expired yet or if no reprieve was given.
113
+ def reprieve_days_left
114
+ return nil unless reprieve_days.to_i > 0 && expired?(reprieve: false)
115
+
116
+ (self.expires_at.next_day(reprieve_days.to_i) - Date.today).to_i
95
117
  end
96
118
 
97
119
  def notify_admins?
@@ -131,6 +153,7 @@ module OpenProject
131
153
  hash["issued_at"] = self.issued_at
132
154
  hash["starts_at"] = self.starts_at
133
155
  hash["expires_at"] = self.expires_at if self.will_expire?
156
+ hash["reprieve_days"] = self.reprieve_days if self.will_expire?
134
157
 
135
158
  hash["notify_admins_at"] = self.notify_admins_at if self.will_notify_admins?
136
159
  hash["notify_users_at"] = self.notify_users_at if self.will_notify_users?
@@ -171,6 +194,16 @@ module OpenProject
171
194
  send("#{attr}=", value)
172
195
  end
173
196
 
197
+ reprieve_days = attributes["reprieve_days"]
198
+
199
+ if will_expire?
200
+ if reprieve_days.nil? && apply_default_reprieve?(version)
201
+ @reprieve_days = 7
202
+ else
203
+ @reprieve_days = reprieve_days.to_i
204
+ end
205
+ end
206
+
174
207
  restrictions = attributes["restrictions"]
175
208
 
176
209
  if restrictions && restrictions.is_a?(Hash)
@@ -196,11 +229,13 @@ module OpenProject
196
229
  #
197
230
  # @param attr [Hash] Parsed token attributes.
198
231
  def read_version(attr)
199
- value = attr["version"]
232
+ value = attr.include?("version") ? attr["version"] : current_gem_version.to_s
200
233
  version = nil
201
234
 
202
- if value.to_s != "-1"
203
- version = value.then { |v| v && Gem::Version.new(v) } || current_gem_version
235
+ if value.to_s == "1"
236
+ version = 1
237
+ elsif value.present? && value.to_s != "-1"
238
+ version = Gem::Version.new value
204
239
 
205
240
  if version > current_gem_version
206
241
  raise ArgumentError, "Version is too new"
@@ -221,5 +256,13 @@ module OpenProject
221
256
  def domain_required_from_version
222
257
  @domain_required_from_version ||= Gem::Version.new('2.0')
223
258
  end
259
+
260
+ ##
261
+ # Reprieve was introduced in version 2.2.0 so could only be set
262
+ # during generation from then onwards. All tokens before that
263
+ # shall apply a default reprieve to be safe.
264
+ def apply_default_reprieve?(version)
265
+ Gem::Version.new(version) < Gem::Version.new("2.2.0")
266
+ end
224
267
  end
225
268
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openproject-token
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenProject GmbH
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-29 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.5'
55
- description:
55
+ description:
56
56
  email: info@openproject.com
57
57
  executables: []
58
58
  extensions: []
@@ -69,7 +69,7 @@ homepage: https://www.openproject.org
69
69
  licenses:
70
70
  - GPL-3.0
71
71
  metadata: {}
72
- post_install_message:
72
+ post_install_message:
73
73
  rdoc_options: []
74
74
  require_paths:
75
75
  - lib
@@ -84,8 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 3.0.3
88
- signing_key:
87
+ rubygems_version: 3.1.2
88
+ signing_key:
89
89
  specification_version: 4
90
90
  summary: OpenProject EE token reader
91
91
  test_files: []