openproject-token 2.1.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/open_project/token/version.rb +1 -1
- data/lib/open_project/token.rb +62 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c70ad73f805a38cc1846b8c5b1db6492efda10e039c0d417f41577ba4aa0c50d
|
4
|
+
data.tar.gz: ddc82e67199f997413a1493eef6518f238821eb5f995cf07d945b7fec95cb8b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd224aeb838bac009ab74e4aa9d31c60891c4d860351c21e18d2bc52aaca39be0bbf008e304b58e842194234cf3e6070b9de2a59f6086fde577abdaaa84a773
|
7
|
+
data.tar.gz: eb3bb63292374c49f3d6cf39bebeb7584c64b91835107f520d995cebb4047e3e285f83481948b209e40e3364f85be909346f362540548fbe017665c47d932b47
|
data/lib/open_project/token.rb
CHANGED
@@ -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
|
-
|
94
|
-
|
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?
|
@@ -111,6 +133,14 @@ module OpenProject
|
|
111
133
|
version && Gem::Version.new(version) >= domain_required_from_version
|
112
134
|
end
|
113
135
|
|
136
|
+
def valid_domain?(input)
|
137
|
+
if domain.is_a?(Regexp)
|
138
|
+
domain.match?(input)
|
139
|
+
else
|
140
|
+
domain == input
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
114
144
|
def restricted?(key = nil)
|
115
145
|
if key
|
116
146
|
restricted? && restrictions.has_key?(key)
|
@@ -131,6 +161,7 @@ module OpenProject
|
|
131
161
|
hash["issued_at"] = self.issued_at
|
132
162
|
hash["starts_at"] = self.starts_at
|
133
163
|
hash["expires_at"] = self.expires_at if self.will_expire?
|
164
|
+
hash["reprieve_days"] = self.reprieve_days if self.will_expire?
|
134
165
|
|
135
166
|
hash["notify_admins_at"] = self.notify_admins_at if self.will_notify_admins?
|
136
167
|
hash["notify_users_at"] = self.notify_users_at if self.will_notify_users?
|
@@ -160,7 +191,7 @@ module OpenProject
|
|
160
191
|
@subscriber = attributes["subscriber"]
|
161
192
|
@mail = attributes["mail"]
|
162
193
|
@company = attributes["company"]
|
163
|
-
@domain = attributes["domain"]
|
194
|
+
@domain = read_domain attributes["domain"]
|
164
195
|
|
165
196
|
date_attribute_keys.each do |attr|
|
166
197
|
value = attributes[attr]
|
@@ -171,6 +202,16 @@ module OpenProject
|
|
171
202
|
send("#{attr}=", value)
|
172
203
|
end
|
173
204
|
|
205
|
+
reprieve_days = attributes["reprieve_days"]
|
206
|
+
|
207
|
+
if will_expire?
|
208
|
+
if reprieve_days.nil? && apply_default_reprieve?(version)
|
209
|
+
@reprieve_days = 7
|
210
|
+
else
|
211
|
+
@reprieve_days = reprieve_days.to_i
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
174
215
|
restrictions = attributes["restrictions"]
|
175
216
|
|
176
217
|
if restrictions && restrictions.is_a?(Hash)
|
@@ -199,7 +240,9 @@ module OpenProject
|
|
199
240
|
value = attr.include?("version") ? attr["version"] : current_gem_version.to_s
|
200
241
|
version = nil
|
201
242
|
|
202
|
-
if value.
|
243
|
+
if value.to_s == "1"
|
244
|
+
version = 1
|
245
|
+
elsif value.present? && value.to_s != "-1"
|
203
246
|
version = Gem::Version.new value
|
204
247
|
|
205
248
|
if version > current_gem_version
|
@@ -210,6 +253,13 @@ module OpenProject
|
|
210
253
|
version
|
211
254
|
end
|
212
255
|
|
256
|
+
def read_domain(input)
|
257
|
+
return input if input.nil? || !(input.start_with?('/') && input.end_with?('/'))
|
258
|
+
|
259
|
+
# Omit the slashes of the input
|
260
|
+
Regexp.new input[1..-2]
|
261
|
+
end
|
262
|
+
|
213
263
|
def date_attribute_keys
|
214
264
|
%w(starts_at issued_at expires_at notify_admins_at notify_users_at block_changes_at)
|
215
265
|
end
|
@@ -221,5 +271,13 @@ module OpenProject
|
|
221
271
|
def domain_required_from_version
|
222
272
|
@domain_required_from_version ||= Gem::Version.new('2.0')
|
223
273
|
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# Reprieve was introduced in version 2.2.0 so could only be set
|
277
|
+
# during generation from then onwards. All tokens before that
|
278
|
+
# shall apply a default reprieve to be safe.
|
279
|
+
def apply_default_reprieve?(version)
|
280
|
+
Gem::Version.new(version) < Gem::Version.new("2.2.0")
|
281
|
+
end
|
224
282
|
end
|
225
283
|
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:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenProject GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.3.7
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: OpenProject EE token reader
|