openproject-token 1.0.2 → 2.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.rb +29 -6
- data/lib/open_project/token/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da90cc05359f099b94484c379973b4c4464b8f9ef7f6d20bdefba2b4fc61537
|
4
|
+
data.tar.gz: 5f87461bbf02ecf0d8c5663b4dba13ea9c511dbd807d8c3e15e4adfe5c040f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd82c0f1815535f7e568d969a1c4e469beaf4d5470014c59496c12e2cd82edf0b9c6e6d9267cfa4b97ef9b6408a737f41fb1d8ae3cdb70c7353ae29f4e7cb940
|
7
|
+
data.tar.gz: ec350f3838ec36b45fb6d0671bac492abd0bf7b5975ced83f2c430b6148274e34d93907525830aa4c5dc44fc2e2182f4092d7bc818d11bfdcd906a77a5411eda
|
data/lib/open_project/token.rb
CHANGED
@@ -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
|
@@ -146,18 +155,19 @@ module OpenProject
|
|
146
155
|
|
147
156
|
def load_attributes(attributes)
|
148
157
|
attributes = Hash[attributes.map { |k, v| [k.to_s, v] }]
|
158
|
+
version = attributes["version"].then { |v| v && Gem::Version.new(v) } || current_gem_version
|
149
159
|
|
150
|
-
|
151
|
-
unless version && version == 1
|
160
|
+
if version > current_gem_version
|
152
161
|
raise ArgumentError, "Version is too new"
|
153
162
|
end
|
154
163
|
|
155
|
-
@version = version
|
164
|
+
@version = version.to_s
|
156
165
|
@subscriber = attributes["subscriber"]
|
157
166
|
@mail = attributes["mail"]
|
167
|
+
@company = attributes["company"]
|
168
|
+
@domain = attributes["domain"]
|
158
169
|
|
159
|
-
|
160
|
-
notify_admins_at notify_users_at block_changes_at).each do |attr|
|
170
|
+
date_attribute_keys.each do |attr|
|
161
171
|
value = attributes[attr]
|
162
172
|
value = Date.parse(value) rescue nil if value.is_a?(String)
|
163
173
|
|
@@ -167,10 +177,23 @@ module OpenProject
|
|
167
177
|
end
|
168
178
|
|
169
179
|
restrictions = attributes["restrictions"]
|
180
|
+
|
170
181
|
if restrictions && restrictions.is_a?(Hash)
|
171
182
|
restrictions = Hash[restrictions.map { |k, v| [k.to_sym, v] }]
|
172
183
|
@restrictions = restrictions
|
173
184
|
end
|
174
185
|
end
|
186
|
+
|
187
|
+
def date_attribute_keys
|
188
|
+
%w(starts_at issued_at expires_at notify_admins_at notify_users_at block_changes_at)
|
189
|
+
end
|
190
|
+
|
191
|
+
def current_gem_version
|
192
|
+
@current_gem_version ||= Gem::Version.new(OpenProject::Token::VERSION.to_s)
|
193
|
+
end
|
194
|
+
|
195
|
+
def domain_required_from_version
|
196
|
+
@domain_required_from_version ||= Gem::Version.new('2.0')
|
197
|
+
end
|
175
198
|
end
|
176
199
|
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:
|
4
|
+
version: '2.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: 2020-05-15 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
|
-
-
|
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.
|
87
|
+
rubygems_version: 3.0.1
|
74
88
|
signing_key:
|
75
89
|
specification_version: 4
|
76
90
|
summary: OpenProject EE token reader
|