mumukit-service 1.0.0 → 2.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/mumukit/service.rb +0 -2
- data/lib/mumukit/service/collection.rb +8 -0
- data/lib/mumukit/service/routes.rb +16 -7
- data/lib/mumukit/service/version.rb +1 -1
- metadata +2 -5
- data/lib/mumukit/service/invalid_slug_format_error.rb +0 -4
- data/lib/mumukit/service/routes/auth.rb +0 -27
- data/lib/mumukit/service/slug.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6bf6480ae3161541ab76818bf3c371d8a33dc58
|
4
|
+
data.tar.gz: 39cf1dbfa393b16978ce16930d00a231504681cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b52f5934b147ad57acd5b5132d35d9470f33c4fff2c90b35aae5316fa230851a3203af658e95a43bf834a26deb7348ffb7dca4f781ac2a7e82c7647bfde1f639
|
7
|
+
data.tar.gz: fc9870456f43db6a7e9a37f20acb7d746d7137f8aa072f376b1ff601dcd542c7b8357ee41f737124214bf977a266d8e3797c71f3bab281025553d262b102d896
|
data/lib/mumukit/service.rb
CHANGED
@@ -11,9 +11,7 @@ end
|
|
11
11
|
|
12
12
|
require 'mumukit/service/version'
|
13
13
|
require_relative './service/id_generator'
|
14
|
-
require_relative './service/slug'
|
15
14
|
require_relative './service/database'
|
16
|
-
require_relative './service/invalid_slug_format_error'
|
17
15
|
require_relative './service/document'
|
18
16
|
require_relative './service/document_array'
|
19
17
|
require_relative './service/document_not_found_error'
|
@@ -90,6 +90,14 @@ module Mumukit::Service
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
+
def upsert_attributes!(query, attribute)
|
94
|
+
mongo_collection.update_one query, {'$set': attribute}, {upsert: true}
|
95
|
+
end
|
96
|
+
|
97
|
+
def update_attributes!(query, attribute)
|
98
|
+
mongo_collection.update_one query, '$set': attribute
|
99
|
+
end
|
100
|
+
|
93
101
|
private
|
94
102
|
|
95
103
|
def validate_presence(args, first)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'sinatra'
|
2
2
|
require 'sinatra/cross_origin'
|
3
3
|
require 'logger'
|
4
|
+
require 'mumukit/auth'
|
4
5
|
|
5
6
|
require 'json'
|
6
7
|
require 'yaml'
|
@@ -26,11 +27,11 @@ helpers do
|
|
26
27
|
|
27
28
|
def slug
|
28
29
|
if route_slug_parts.present?
|
29
|
-
Mumukit::
|
30
|
+
Mumukit::Auth::Slug.join(*route_slug_parts)
|
30
31
|
elsif subject
|
31
|
-
Mumukit::
|
32
|
+
Mumukit::Auth::Slug.parse(subject.slug)
|
32
33
|
elsif json_body
|
33
|
-
Mumukit::
|
34
|
+
Mumukit::Auth::Slug.parse(json_body['slug'])
|
34
35
|
else
|
35
36
|
raise Mumukit::Service::InvalidSlugFormatError.new('Slug not available')
|
36
37
|
end
|
@@ -59,10 +60,6 @@ error JSON::ParserError do
|
|
59
60
|
halt 400
|
60
61
|
end
|
61
62
|
|
62
|
-
error Mumukit::Service::InvalidSlugFormatError do
|
63
|
-
halt 400
|
64
|
-
end
|
65
|
-
|
66
63
|
error Mumukit::Service::DocumentValidationError do
|
67
64
|
halt 400
|
68
65
|
end
|
@@ -71,6 +68,18 @@ error Mumukit::Service::DocumentNotFoundError do
|
|
71
68
|
halt 404
|
72
69
|
end
|
73
70
|
|
71
|
+
error Mumukit::Auth::InvalidTokenError do
|
72
|
+
halt 401
|
73
|
+
end
|
74
|
+
|
75
|
+
error Mumukit::Auth::UnauthorizedAccessError do
|
76
|
+
halt 403
|
77
|
+
end
|
78
|
+
|
79
|
+
error Mumukit::Auth::InvalidSlugFormatError do
|
80
|
+
halt 400
|
81
|
+
end
|
82
|
+
|
74
83
|
options '*' do
|
75
84
|
response.headers['Allow'] = settings.allow_methods.map { |it| it.to_s.upcase }.join(',')
|
76
85
|
response.headers['Access-Control-Allow-Headers'] = 'X-Mumuki-Auth-Token, X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept, Authorization'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumukit-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -163,10 +163,7 @@ files:
|
|
163
163
|
- lib/mumukit/service/document_validation_error.rb
|
164
164
|
- lib/mumukit/service/env.rb
|
165
165
|
- lib/mumukit/service/id_generator.rb
|
166
|
-
- lib/mumukit/service/invalid_slug_format_error.rb
|
167
166
|
- lib/mumukit/service/routes.rb
|
168
|
-
- lib/mumukit/service/routes/auth.rb
|
169
|
-
- lib/mumukit/service/slug.rb
|
170
167
|
- lib/mumukit/service/version.rb
|
171
168
|
- mumukit-service.gemspec
|
172
169
|
homepage: https://github.com/mumuki/mumukit-service
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'mumukit/auth'
|
2
|
-
|
3
|
-
helpers do
|
4
|
-
def authorization_header
|
5
|
-
env['HTTP_AUTHORIZATION']
|
6
|
-
end
|
7
|
-
|
8
|
-
def token
|
9
|
-
@token ||= Mumukit::Auth::Token.decode_header(authorization_header).tap(&:verify_client!)
|
10
|
-
end
|
11
|
-
|
12
|
-
def permissions
|
13
|
-
@permissions ||= token.permissions
|
14
|
-
end
|
15
|
-
|
16
|
-
def protect!(scope)
|
17
|
-
permissions.protect! scope, slug.to_s
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
error Mumukit::Auth::InvalidTokenError do
|
22
|
-
halt 401
|
23
|
-
end
|
24
|
-
|
25
|
-
error Mumukit::Auth::UnauthorizedAccessError do
|
26
|
-
halt 403
|
27
|
-
end
|
data/lib/mumukit/service/slug.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module Mumukit::Service
|
2
|
-
class Slug
|
3
|
-
attr_accessor :organization, :repository
|
4
|
-
|
5
|
-
def initialize(organization, repository)
|
6
|
-
@organization = organization
|
7
|
-
@repository = repository
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
"#{organization}/#{repository}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def bibliotehca_guide_web_hook_url
|
15
|
-
"http://bibliotheca.mumuki.io/guides/import/#{to_s}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def bibliotehca_book_web_hook_url
|
19
|
-
"http://bibliotheca.mumuki.io/books/import/#{to_s}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def classroom_course_url
|
23
|
-
"http://classroom.mumuki.io/courses/#{to_s}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.from(slug)
|
27
|
-
validate_slug! slug
|
28
|
-
|
29
|
-
self.new *slug.split('/')
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def self.validate_slug!(slug)
|
35
|
-
unless slug =~ /.*\/.*/
|
36
|
-
raise Mumukit::Service::InvalidSlugFormatError, 'Slug must be in organization/repository format'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
|