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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 897f8ec6497b490ab49e7bacfa160058f131e3a5
4
- data.tar.gz: a25730383fcc8a862d4ccbdf2753aa2eb1614af8
3
+ metadata.gz: d6bf6480ae3161541ab76818bf3c371d8a33dc58
4
+ data.tar.gz: 39cf1dbfa393b16978ce16930d00a231504681cf
5
5
  SHA512:
6
- metadata.gz: 3b0da98eba909a32141c4e6e49922962551adf6c7654637098903d476a746e7299f15430919f18481eb8703483fc99cd34cd3c7bf7a2c2c27ce1ae6261afca70
7
- data.tar.gz: efe600c5cddd70204ae571c726c125291a9e88e135bf13476eb601a3af238391155889b794295afd856a1198351f31299e5e6b7ca6e4a08932317e586df23f9b
6
+ metadata.gz: b52f5934b147ad57acd5b5132d35d9470f33c4fff2c90b35aae5316fa230851a3203af658e95a43bf834a26deb7348ffb7dca4f781ac2a7e82c7647bfde1f639
7
+ data.tar.gz: fc9870456f43db6a7e9a37f20acb7d746d7137f8aa072f376b1ff601dcd542c7b8357ee41f737124214bf977a266d8e3797c71f3bab281025553d262b102d896
@@ -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::Service::Slug.new(*route_slug_parts)
30
+ Mumukit::Auth::Slug.join(*route_slug_parts)
30
31
  elsif subject
31
- Mumukit::Service::Slug.from(subject.slug)
32
+ Mumukit::Auth::Slug.parse(subject.slug)
32
33
  elsif json_body
33
- Mumukit::Service::Slug.from(json_body['slug'])
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'
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Service
3
- VERSION = '1.0.0'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
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: 1.0.0
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: 2016-12-21 00:00:00.000000000 Z
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,4 +0,0 @@
1
- module Mumukit::Service
2
- class InvalidSlugFormatError < StandardError
3
- end
4
- end
@@ -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
@@ -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
-