openproject-token 1.0.1 → 2.1.1

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
- SHA1:
3
- metadata.gz: 0f564f673033235bcf2582b7308be69ce507e58d
4
- data.tar.gz: d9ad6a858ba3d9a066ae7dbc0fb3f930b220b748
2
+ SHA256:
3
+ metadata.gz: 1468e154b8c769ea67d98d887da8b9e00c6e830e04b3375a0622c0137afdaeeb
4
+ data.tar.gz: 8d6197c22e207b8882b7eaab394b5a24fc16e403d9b46c43ee360f395b7b595c
5
5
  SHA512:
6
- metadata.gz: e60ba554b193fb0e3e2dc0e0fb6733f7c293022731d6ad269950f1edad89d171d0ddb5e0063e1b2f9eda312e71d927510836a53eaefc3694037b7deb6f553229
7
- data.tar.gz: 721439cc7e07bdd6daaedf5d17bc8cdcf2a5c55a8a41b3e4569cb46cd67d120e37b63e1051bf66da134d536cab8f000b61550027151f7f6995202f05d6ec5067
6
+ metadata.gz: 1550e4748618f99e45f3653d8c34360e4f7bb0803a5850f5d89c9b705cd87a9faf217e36ced06f5c5648134c417bc72404cfb6f4a2a910939b0a015a92bf6264
7
+ data.tar.gz: 15662a9656073de5d1c0a8b8af5e72383aca6436233349c202b29c0262ea208a4afe2a77e6e8b109d052a84c40c636b19fd6a7ee03b49a886442130b57c47d36
@@ -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(v)
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.1"
3
+ VERSION = "2.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openproject-token
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenProject GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ files:
67
67
  - lib/openproject-token.rb
68
68
  homepage: https://www.openproject.org
69
69
  licenses:
70
- - GPLv3
70
+ - GPL-3.0
71
71
  metadata: {}
72
72
  post_install_message:
73
73
  rdoc_options: []
@@ -84,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubyforge_project:
88
- rubygems_version: 2.4.5.1
87
+ rubygems_version: 3.0.3
89
88
  signing_key:
90
89
  specification_version: 4
91
90
  summary: OpenProject EE token reader