osm 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/lib/osm/due_badges.rb +1 -1
- data/lib/osm/evening.rb +2 -2
- data/lib/osm/event.rb +8 -8
- data/lib/osm/flexi_record.rb +2 -2
- data/lib/osm/member.rb +1 -1
- data/lib/osm/model.rb +13 -1
- data/lib/osm/register.rb +2 -2
- data/lib/osm/section.rb +2 -2
- data/version.rb +1 -1
- metadata +17 -22
data/CHANGELOG.md
CHANGED
data/lib/osm/due_badges.rb
CHANGED
@@ -39,7 +39,7 @@ module Osm
|
|
39
39
|
term_id = (term.nil? ? Osm::Term.get_current_term_for_section(api, section, options) : term).to_i
|
40
40
|
cache_key = ['due_badges', section.id, term_id]
|
41
41
|
|
42
|
-
if !options[:no_cache] && cache_exist?(api, cache_key) &&
|
42
|
+
if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section.id, :badge).include?(:read)
|
43
43
|
return cache_read(api, cache_key)
|
44
44
|
end
|
45
45
|
|
data/lib/osm/evening.rb
CHANGED
@@ -68,7 +68,7 @@ module Osm
|
|
68
68
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
|
69
69
|
cache_key = ['programme', section_id, term_id]
|
70
70
|
|
71
|
-
if !options[:no_cache] && cache_exist?(api, cache_key) &&
|
71
|
+
if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :programme).include?(:read)
|
72
72
|
return cache_read(api, cache_key)
|
73
73
|
end
|
74
74
|
|
@@ -186,7 +186,7 @@ module Osm
|
|
186
186
|
section = Osm::Section.get(api, section_id)
|
187
187
|
cache_key = ['badge_requirements', section.id, id]
|
188
188
|
|
189
|
-
if !options[:no_cache] && self.class.cache_exist?(api, cache_key) &&
|
189
|
+
if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && get_user_permission(api, section_id, :programme).include?(:read)
|
190
190
|
return self.class.cache_read(api, cache_key)
|
191
191
|
end
|
192
192
|
|
data/lib/osm/event.rb
CHANGED
@@ -58,7 +58,7 @@ module Osm
|
|
58
58
|
cache_key = ['events', section_id]
|
59
59
|
events = nil
|
60
60
|
|
61
|
-
if !options[:no_cache] && cache_exist?(api, cache_key) &&
|
61
|
+
if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :events).include?(:read)
|
62
62
|
return cache_read(api, cache_key)
|
63
63
|
end
|
64
64
|
|
@@ -109,7 +109,7 @@ module Osm
|
|
109
109
|
section_id = section.to_i
|
110
110
|
cache_key = ['event', event_id]
|
111
111
|
|
112
|
-
if !options[:no_cache] && cache_exist?(api, cache_key) &&
|
112
|
+
if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :events).include?(:read)
|
113
113
|
return cache_read(api, cache_key)
|
114
114
|
end
|
115
115
|
|
@@ -130,7 +130,7 @@ module Osm
|
|
130
130
|
def self.create(api, parameters)
|
131
131
|
event = new(parameters)
|
132
132
|
raise ObjectIsInvalid, 'event is invalid' unless event.valid?
|
133
|
-
raise Forbidden, 'you do not have permission to write to events for this section' unless
|
133
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, event.section_id, :events).include?(:write)
|
134
134
|
|
135
135
|
data = api.perform_query("events.php?action=addEvent§ionid=#{event.section_id}", {
|
136
136
|
'name' => event.name,
|
@@ -159,7 +159,7 @@ module Osm
|
|
159
159
|
# @param [Osm::Api] api The api to use to make the request
|
160
160
|
# @return [Boolean] wether the update succedded
|
161
161
|
def update(api)
|
162
|
-
raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.
|
162
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.get_user_permission(api, section_id, :events).include?(:write)
|
163
163
|
|
164
164
|
data = api.perform_query("events.php?action=addEvent§ionid=#{section_id}", {
|
165
165
|
'eventid' => id,
|
@@ -184,7 +184,7 @@ module Osm
|
|
184
184
|
# @param [Osm::Api] api The api to use to make the request
|
185
185
|
# @return [Boolean] wether the delete succedded
|
186
186
|
def delete(api)
|
187
|
-
raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.
|
187
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.get_user_permission(api, section_id, :events).include?(:write)
|
188
188
|
|
189
189
|
data = api.perform_query("events.php?action=deleteEvent§ionid=#{section_id}&eventid=#{id}")
|
190
190
|
|
@@ -206,7 +206,7 @@ module Osm
|
|
206
206
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
|
207
207
|
cache_key = ['event_attendance', id]
|
208
208
|
|
209
|
-
if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && self.class.
|
209
|
+
if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && self.class.get_user_permission(api, section_id, :events).include?(:read)
|
210
210
|
return self.class.cache_read(api, cache_key)
|
211
211
|
end
|
212
212
|
|
@@ -242,7 +242,7 @@ module Osm
|
|
242
242
|
# @return [Boolean] wether the update succedded
|
243
243
|
def add_field(api, label)
|
244
244
|
raise ArgumentIsInvalid, 'label is invalid' if label.blank?
|
245
|
-
raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.
|
245
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless self.class.get_user_permission(api, section_id, :events).include?(:write)
|
246
246
|
|
247
247
|
data = api.perform_query("events.php?action=addColumn§ionid=#{section_id}&eventid=#{id}", {
|
248
248
|
'columnName' => label
|
@@ -299,7 +299,7 @@ module Osm
|
|
299
299
|
# @return [Boolean] if the operation suceeded or not
|
300
300
|
def update(api, field_id)
|
301
301
|
raise ArgumentIsInvalid, 'field_id is invalid' unless field_id.match(/\Af_\d+\Z/) || field_id.eql?('attending')
|
302
|
-
raise Forbidden, 'you do not have permission to write to events for this section' unless Osm::Model.
|
302
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless Osm::Model.get_user_permission(api, event.section_id, :events).include?(:write)
|
303
303
|
|
304
304
|
data = api.perform_query("events.php?action=updateScout", {
|
305
305
|
'scoutid' => member_id,
|
data/lib/osm/flexi_record.rb
CHANGED
@@ -12,7 +12,7 @@ module Osm
|
|
12
12
|
section_id = section.to_i
|
13
13
|
cache_key = ['flexi_record_fields', id]
|
14
14
|
|
15
|
-
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.
|
15
|
+
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.get_user_permission(api, section_id, :flexi).include?(:read)
|
16
16
|
return Osm::Model.cache_read(api, cache_key)
|
17
17
|
end
|
18
18
|
|
@@ -45,7 +45,7 @@ module Osm
|
|
45
45
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
|
46
46
|
cache_key = ['flexi_record_data', id, term_id]
|
47
47
|
|
48
|
-
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.
|
48
|
+
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.get_user_permission(api, section.id, :flexi).include?(:read)
|
49
49
|
return Osm::Model.cache_read(api, cache_key)
|
50
50
|
end
|
51
51
|
|
data/lib/osm/member.rb
CHANGED
@@ -152,7 +152,7 @@ module Osm
|
|
152
152
|
section_id = section.to_i
|
153
153
|
cache_key = ['members', section_id, term_id]
|
154
154
|
|
155
|
-
if !options[:no_cache] && cache_exist?(api, cache_key) &&
|
155
|
+
if !options[:no_cache] && cache_exist?(api, cache_key) && get_user_permission(api, section_id, :member).include?(:read)
|
156
156
|
return cache_read(api, cache_key)
|
157
157
|
end
|
158
158
|
|
data/lib/osm/model.rb
CHANGED
@@ -75,7 +75,19 @@ module Osm
|
|
75
75
|
def self.get_user_permissions(api, section_id=nil, options={})
|
76
76
|
key = ['permissions', api.user_id]
|
77
77
|
permissions = (!options[:no_cache] && cache_exist?(api, key)) ? cache_read(api, key) : Osm::Section.fetch_user_permissions(api)
|
78
|
-
|
78
|
+
permissions ||= {}
|
79
|
+
return section_id.nil? ? (permissions || {}) : (permissions[section_id] || {})
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get an access permission for an API user
|
83
|
+
# @param [Osm::Api] The api to use to make the request
|
84
|
+
# @param [Fixnum, nil] section_id to get permissions for, if nil a Hash of all section's permissions is returned
|
85
|
+
# @param [Symbol] permission
|
86
|
+
# @!macro options_get
|
87
|
+
# @return [Array<Symbol>] the actions the user can perform for the provided permission
|
88
|
+
def self.get_user_permission(api, section_id, permission, options={})
|
89
|
+
permissions = get_user_permissions(api, section_id, options)[permission]
|
90
|
+
return (permissions || [])
|
79
91
|
end
|
80
92
|
|
81
93
|
# Set access permission for an API user
|
data/lib/osm/register.rb
CHANGED
@@ -13,7 +13,7 @@ module Osm
|
|
13
13
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
|
14
14
|
cache_key = ['register_structure', section_id, term_id]
|
15
15
|
|
16
|
-
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.
|
16
|
+
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.get_user_permission(api, section_id, :register).include?(:read)
|
17
17
|
return Osm::Model.cache_read(api, cache_key)
|
18
18
|
end
|
19
19
|
|
@@ -45,7 +45,7 @@ module Osm
|
|
45
45
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
|
46
46
|
cache_key = ['register_attendance', section_id, term_id]
|
47
47
|
|
48
|
-
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.
|
48
|
+
if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key) && Osm::Model.get_user_permission(api, section_id, :register).include?(:read)
|
49
49
|
return Osm::Model.cache_read(api, cache_key)
|
50
50
|
end
|
51
51
|
|
data/lib/osm/section.rb
CHANGED
@@ -217,7 +217,7 @@ module Osm
|
|
217
217
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, self).id : term.to_i
|
218
218
|
cache_key = ['badge_stock', id, term_id]
|
219
219
|
|
220
|
-
if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && self.class.
|
220
|
+
if !options[:no_cache] && self.class.cache_exist?(api, cache_key) && self.class.get_user_permission(api, self, :badge).include?(:read)
|
221
221
|
return self.class.cache_read(api, cache_key)
|
222
222
|
end
|
223
223
|
|
@@ -296,7 +296,7 @@ module Osm
|
|
296
296
|
}
|
297
297
|
|
298
298
|
return permissions.inject({}) do |new_hash, (key, value)|
|
299
|
-
new_hash[key.to_sym] = (permissions_map[value] || [])
|
299
|
+
new_hash[key.to_sym] = (permissions_map[value.to_i] || [])
|
300
300
|
new_hash
|
301
301
|
end
|
302
302
|
end
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &78318930 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *78318930
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &78318540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.9'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *78318540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: active_attr
|
38
|
-
requirement: &
|
38
|
+
requirement: &78318210 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.6'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *78318210
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activemodel
|
49
|
-
requirement: &
|
49
|
+
requirement: &78317870 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.2'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *78317870
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &78317510 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0.9'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *78317510
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &78317150 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '2.11'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *78317150
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: fakeweb
|
82
|
-
requirement: &
|
82
|
+
requirement: &78316920 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '1.3'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *78316920
|
91
91
|
description: Use the Online Scout Manager API (https://www.onlinescoutmanager.co.uk)
|
92
92
|
to retrieve and save data.
|
93
93
|
email:
|
@@ -149,18 +149,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
- - ! '>='
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
|
-
segments:
|
153
|
-
- 0
|
154
|
-
hash: -198994829
|
155
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
153
|
none: false
|
157
154
|
requirements:
|
158
155
|
- - ! '>='
|
159
156
|
- !ruby/object:Gem::Version
|
160
157
|
version: '0'
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
hash: -198994829
|
164
158
|
requirements: []
|
165
159
|
rubyforge_project: osm
|
166
160
|
rubygems_version: 1.8.10
|
@@ -168,3 +162,4 @@ signing_key:
|
|
168
162
|
specification_version: 3
|
169
163
|
summary: Use the Online Scout Manager API
|
170
164
|
test_files: []
|
165
|
+
has_rdoc:
|