openproject-token 1.0.2 → 2.1.2

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: d055c8358ab2666105256d7a71247b3f0235e32ceaa6fb5588fe3af7846213ce
4
- data.tar.gz: 2a9ca23046c2d5dd0d48ecaa232393b7598fe149bfacbb76eef5fdf6a435e741
3
+ metadata.gz: 1ed575580b33d7177820ffda871a4fd406f8fd43140703c1aad12ebcdbddde8c
4
+ data.tar.gz: e12c8de3670fd3088cfdca2d269dfd421ce64fc0a915d55ee0963519c62f81c0
5
5
  SHA512:
6
- metadata.gz: 1d051dd136b1ab29adcc0604098fd365c2039152a6f299a548dc95bfc53021a74c4a61ff81a914f723d6620c2fd646993942450ba466f07ad6d5e0266aa441e5
7
- data.tar.gz: fd21a30af2d6ee77bf8ce114ca0c95eeb3d8a656bcb3816bfdaa35b2a78d154843b13db896115f6dbd2f4d30e939b3aa900697b6a748e8e8f4b6c3fc1784ea86
6
+ metadata.gz: 1d7598d1e1190514985bcfc5c61377aac11fa6fff26a9d7acb3464436a1a7ac1cf3efc4d01eea6fcb8756025189458a6cf00c7e2d07721f245a1ce2378651037
7
+ data.tar.gz: 57d526430d85dda036614a71352e7bf677569f679e5c8314a42ff82411c033acbc7d17abd5d1500c4aaedbb9b9c622557152ae01eef503b2df1c8abe4e59fbb7
@@ -49,13 +49,15 @@ module OpenProject
49
49
  include ActiveModel::Validations
50
50
 
51
51
  attr_reader :version
52
- attr_accessor :subscriber, :mail
52
+ attr_accessor :subscriber, :mail, :company, :domain
53
53
  attr_accessor :starts_at, :issued_at, :expires_at
54
54
  attr_accessor :notify_admins_at, :notify_users_at, :block_changes_at
55
55
  attr_accessor :restrictions
56
56
 
57
57
  validates_presence_of :subscriber
58
58
  validates_presence_of :mail
59
+ validates_presence_of :company, allow_blank: true
60
+ validates_presence_of :domain, if: :validate_domain?
59
61
 
60
62
  validates_each(
61
63
  :starts_at, :issued_at, :expires_at, :notify_admins_at, :notify_users_at, :block_changes_at,
@@ -104,6 +106,11 @@ module OpenProject
104
106
  will_block_changes? && Date.today >= self.block_changes_at
105
107
  end
106
108
 
109
+ # tokens with no version or a version lower than 2.0 don't have the attributes company or domain
110
+ def validate_domain?
111
+ version && Gem::Version.new(version) >= domain_required_from_version
112
+ end
113
+
107
114
  def restricted?(key = nil)
108
115
  if key
109
116
  restricted? && restrictions.has_key?(key)
@@ -118,6 +125,8 @@ module OpenProject
118
125
  hash["version"] = self.version
119
126
  hash["subscriber"] = self.subscriber
120
127
  hash["mail"] = self.mail
128
+ hash["company"] = self.company
129
+ hash["domain"] = self.domain
121
130
 
122
131
  hash["issued_at"] = self.issued_at
123
132
  hash["starts_at"] = self.starts_at
@@ -147,17 +156,13 @@ module OpenProject
147
156
  def load_attributes(attributes)
148
157
  attributes = Hash[attributes.map { |k, v| [k.to_s, v] }]
149
158
 
150
- version = attributes["version"] || 1
151
- unless version && version == 1
152
- raise ArgumentError, "Version is too new"
153
- end
154
-
155
- @version = version
159
+ @version = read_version attributes
156
160
  @subscriber = attributes["subscriber"]
157
161
  @mail = attributes["mail"]
162
+ @company = attributes["company"]
163
+ @domain = attributes["domain"]
158
164
 
159
- %w(starts_at issued_at expires_at
160
- notify_admins_at notify_users_at block_changes_at).each do |attr|
165
+ date_attribute_keys.each do |attr|
161
166
  value = attributes[attr]
162
167
  value = Date.parse(value) rescue nil if value.is_a?(String)
163
168
 
@@ -167,10 +172,54 @@ module OpenProject
167
172
  end
168
173
 
169
174
  restrictions = attributes["restrictions"]
175
+
170
176
  if restrictions && restrictions.is_a?(Hash)
171
177
  restrictions = Hash[restrictions.map { |k, v| [k.to_sym, v] }]
172
178
  @restrictions = restrictions
173
179
  end
174
180
  end
181
+
182
+ ##
183
+ # Reads the version from the given attributes hash.
184
+ # Besides the usual values it allows for a special value `-1`.
185
+ # This is then results in the version being `nil` specifically rather than
186
+ # the current gem version by default.
187
+ #
188
+ # This way the generated token will get what ever version the importing party
189
+ # has. This is important due to a bug in openproject-token 1.x where any version
190
+ # other than `nil` (or the integer literal 1) results in a "Version is too new" error.
191
+ # This affects all OpenProject installations with a version older than 10.6
192
+ # which will run into internal server errors trying to activate their Enterprise
193
+ # tokens due to this.
194
+ #
195
+ # Generating tokens with version `-1` prevents that.
196
+ #
197
+ # @param attr [Hash] Parsed token attributes.
198
+ def read_version(attr)
199
+ value = attr["version"]
200
+ version = nil
201
+
202
+ if value.present? && value.to_s != "-1"
203
+ version = Gem::Version.new value
204
+
205
+ if version > current_gem_version
206
+ raise ArgumentError, "Version is too new"
207
+ end
208
+ end
209
+
210
+ version
211
+ end
212
+
213
+ def date_attribute_keys
214
+ %w(starts_at issued_at expires_at notify_admins_at notify_users_at block_changes_at)
215
+ end
216
+
217
+ def current_gem_version
218
+ @current_gem_version ||= Gem::Version.new(OpenProject::Token::VERSION.to_s)
219
+ end
220
+
221
+ def domain_required_from_version
222
+ @domain_required_from_version ||= Gem::Version.new('2.0')
223
+ end
175
224
  end
176
225
  end
@@ -1,5 +1,5 @@
1
1
  module OpenProject
2
2
  class Token
3
- VERSION = "1.0.2"
3
+ VERSION = "2.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openproject-token
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenProject GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +67,7 @@ files:
53
67
  - lib/openproject-token.rb
54
68
  homepage: https://www.openproject.org
55
69
  licenses:
56
- - GPLv3
70
+ - GPL-3.0
57
71
  metadata: {}
58
72
  post_install_message:
59
73
  rdoc_options: []
@@ -70,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
84
  - !ruby/object:Gem::Version
71
85
  version: '0'
72
86
  requirements: []
73
- rubygems_version: 3.0.2
87
+ rubygems_version: 3.0.3
74
88
  signing_key:
75
89
  specification_version: 4
76
90
  summary: OpenProject EE token reader