mumuki-bibliotheca 6.1.1 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -11
- data/lib/mumuki/bibliotheca/engine.rb +1 -1
- data/lib/mumuki/bibliotheca/sinatra/books.rb +23 -21
- data/lib/mumuki/bibliotheca/sinatra/guides.rb +35 -33
- data/lib/mumuki/bibliotheca/sinatra/languages.rb +9 -7
- data/lib/mumuki/bibliotheca/sinatra/organization.rb +4 -2
- data/lib/mumuki/bibliotheca/sinatra/topics.rb +23 -21
- data/lib/mumuki/bibliotheca/sinatra.rb +119 -118
- data/lib/mumuki/bibliotheca/version.rb +1 -1
- metadata +23 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3452b76785a90e339640007046881e3809e48c6ce158eee40eeb65b6752d41d
|
|
4
|
+
data.tar.gz: de7f3eaaec9d4a7374b092bd8e96d23b4b71f36806aa1d45f6d64bd5bb1a0882
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9dd4c6cc8910b5fb34a7ff19f2895d7b6d8f27c6ae35a50759fbc151a8566e57edc172fdfbb1f3e81ccba893561f81bc2dcba7d4b5d4210539f07daede005ff0
|
|
7
|
+
data.tar.gz: dcbda9975fa69aaaed8c335655976736bd29f92fcee7fcf73518832a8b72158fc891ef6140f59c041096bd602ebee694058cd100bc5ec9d9f409c7226b4482ad
|
data/README.md
CHANGED
|
@@ -19,22 +19,17 @@ Bibliotheca is a service for storing Mumuki content - Books, Topics and Guides.
|
|
|
19
19
|
## Preparing environment
|
|
20
20
|
|
|
21
21
|
### 1. Install essentials and base libraries
|
|
22
|
-
|
|
23
|
-
> First, we need to install some software: MongoDB and some common Ruby on Rails native dependencies
|
|
24
|
-
|
|
25
|
-
1. Follow [MongoDB installation guide](https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/)
|
|
26
|
-
2. Run:
|
|
22
|
+
> First, we need to install some software: [PostgreSQL](https://www.postgresql.org) database, [RabbitMQ](https://www.rabbitmq.com/) queue, and some common Ruby on Rails native dependencies
|
|
27
23
|
|
|
28
24
|
```bash
|
|
29
|
-
sudo apt-get install autoconf curl git build-essential libssl-dev autoconf bison libreadline6 libreadline6-dev zlib1g zlib1g-dev
|
|
25
|
+
sudo apt-get install autoconf curl git build-essential libssl-dev autoconf bison libreadline6 libreadline6-dev zlib1g zlib1g-dev postgresql libpq-dev rabbitmq-server
|
|
30
26
|
```
|
|
31
27
|
|
|
32
28
|
### 2. Install rbenv
|
|
33
|
-
|
|
34
29
|
> [rbenv](https://github.com/rbenv/rbenv) is a ruby versions manager, similar to rvm, nvm, and so on.
|
|
35
30
|
|
|
36
31
|
```bash
|
|
37
|
-
curl https://
|
|
32
|
+
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
|
|
38
33
|
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc # or .bash_profile
|
|
39
34
|
echo 'eval "$(rbenv init -)"' >> ~/.bashrc # or .bash_profile
|
|
40
35
|
```
|
|
@@ -48,7 +43,6 @@ rbenv install 2.3.1
|
|
|
48
43
|
rbenv global 2.3.1
|
|
49
44
|
rbenv rehash
|
|
50
45
|
gem install bundler
|
|
51
|
-
gem install escualo
|
|
52
46
|
```
|
|
53
47
|
|
|
54
48
|
### 4. Clone this repository
|
|
@@ -56,8 +50,27 @@ gem install escualo
|
|
|
56
50
|
> Because, err... we need to clone this repostory before developing it :stuck_out_tongue:
|
|
57
51
|
|
|
58
52
|
```bash
|
|
59
|
-
git clone https://github.com/mumuki/mumuki-bibliotheca-api
|
|
60
|
-
cd bibliotheca-api
|
|
53
|
+
git clone https://github.com/mumuki/mumuki-bibliotheca-api
|
|
54
|
+
cd mumuki-bibliotheca-api
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 5. Install and setup database
|
|
58
|
+
|
|
59
|
+
> We need to create a PostgreSQL role - AKA a user - who will be used by Laboratory to create and access the database
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# create db user for linux users
|
|
63
|
+
sudo -u postgres psql <<EOF
|
|
64
|
+
create role mumuki with createdb login password 'mumuki';
|
|
65
|
+
EOF
|
|
66
|
+
|
|
67
|
+
# create db user for mac users
|
|
68
|
+
psql postgres
|
|
69
|
+
#once inside postgres server
|
|
70
|
+
create role mumuki with createdb login password 'mumuki';
|
|
71
|
+
|
|
72
|
+
# create schema and initial development data
|
|
73
|
+
./devinit
|
|
61
74
|
```
|
|
62
75
|
|
|
63
76
|
## Installing and Running
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
class Mumuki::Bibliotheca::App < Sinatra::Application
|
|
2
|
+
helpers do
|
|
3
|
+
def list_books(books)
|
|
4
|
+
{ books: books.as_json(only: [:name, :slug, :chapters]) }
|
|
5
|
+
end
|
|
4
6
|
end
|
|
5
|
-
end
|
|
6
7
|
|
|
7
|
-
get '/books' do
|
|
8
|
-
|
|
9
|
-
end
|
|
8
|
+
get '/books' do
|
|
9
|
+
list_books Book.all
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
get '/books/writable' do
|
|
12
|
-
|
|
13
|
-
end
|
|
12
|
+
get '/books/writable' do
|
|
13
|
+
list_books Book.allowed(current_user.permissions)
|
|
14
|
+
end
|
|
14
15
|
|
|
15
|
-
get '/books/:organization/:repository' do
|
|
16
|
-
|
|
17
|
-
end
|
|
16
|
+
get '/books/:organization/:repository' do
|
|
17
|
+
Book.find_by_slug!(slug.to_s).to_resource_h
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
post '/books' do
|
|
20
|
-
|
|
21
|
-
end
|
|
20
|
+
post '/books' do
|
|
21
|
+
upsert! :book
|
|
22
|
+
end
|
|
22
23
|
|
|
23
|
-
post '/book/:organization/:repository/fork' do
|
|
24
|
-
|
|
25
|
-
end
|
|
24
|
+
post '/book/:organization/:repository/fork' do
|
|
25
|
+
fork! Book
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
delete '/books/:organization/:repository' do
|
|
28
|
-
|
|
28
|
+
delete '/books/:organization/:repository' do
|
|
29
|
+
delete! Book
|
|
30
|
+
end
|
|
29
31
|
end
|
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
class Mumuki::Bibliotheca::App < Sinatra::Application
|
|
2
|
+
helpers do
|
|
3
|
+
def list_guides(guides)
|
|
4
|
+
{ guides: guides.map { |it| it.as_json(only: [:name, :slug, :type]).merge(language: it.language.name) } }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def slice_guide_resource_h_for_api(guide)
|
|
8
|
+
guide.merge(language: guide.dig(:language, :name)).merge(exercises: guide[:exercises].map { |it| it.tap { |it| it[:language] = it.dig(:language, :name) if it[:language]}})
|
|
9
|
+
end
|
|
4
10
|
end
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
get '/guides' do
|
|
13
|
+
list_guides Guide.visible(current_user&.permissions)
|
|
8
14
|
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
get '/guides' do
|
|
12
|
-
list_guides Guide.visible(current_user&.permissions)
|
|
13
|
-
end
|
|
14
15
|
|
|
15
|
-
get '/guides/writable' do
|
|
16
|
-
|
|
17
|
-
end
|
|
16
|
+
get '/guides/writable' do
|
|
17
|
+
list_guides Guide.allowed(current_user&.permissions)
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
delete '/guides/:organization/:repository' do
|
|
20
|
-
|
|
21
|
-
end
|
|
20
|
+
delete '/guides/:organization/:repository' do
|
|
21
|
+
delete! Guide
|
|
22
|
+
end
|
|
22
23
|
|
|
23
|
-
get '/guides/:organization/:repository/markdown' do
|
|
24
|
-
|
|
25
|
-
end
|
|
24
|
+
get '/guides/:organization/:repository/markdown' do
|
|
25
|
+
slice_guide_resource_h_for_api Guide.find_by_slug!(slug.to_s).to_markdownified_resource_h
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
get '/guides/:organization/:repository' do
|
|
28
|
-
|
|
29
|
-
end
|
|
28
|
+
get '/guides/:organization/:repository' do
|
|
29
|
+
slice_guide_resource_h_for_api Guide.find_by_slug!(slug.to_s).to_resource_h
|
|
30
|
+
end
|
|
30
31
|
|
|
31
|
-
post '/guides' do
|
|
32
|
-
|
|
33
|
-
end
|
|
32
|
+
post '/guides' do
|
|
33
|
+
upsert! :guide
|
|
34
|
+
end
|
|
34
35
|
|
|
35
|
-
post '/guides/import/:organization/:repository' do
|
|
36
|
-
|
|
37
|
-
end
|
|
36
|
+
post '/guides/import/:organization/:repository' do
|
|
37
|
+
history_syncer.locate_and_import! :guide, slug.to_s
|
|
38
|
+
end
|
|
38
39
|
|
|
39
|
-
post '/guides/:organization/:repository/assets' do
|
|
40
|
-
|
|
41
|
-
end
|
|
40
|
+
post '/guides/:organization/:repository/assets' do
|
|
41
|
+
Mumuki::Bibliotheca.upload_asset! slug, json_body['filename'], json_body['content']
|
|
42
|
+
end
|
|
42
43
|
|
|
43
|
-
post '/guides/:organization/:repository/fork' do
|
|
44
|
-
|
|
44
|
+
post '/guides/:organization/:repository/fork' do
|
|
45
|
+
fork! Guide
|
|
46
|
+
end
|
|
45
47
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
class Mumuki::Bibliotheca::App < Sinatra::Application
|
|
2
|
+
get '/languages' do
|
|
3
|
+
{ languages: Language.all.map { |it| transform(it) } }
|
|
4
|
+
end
|
|
4
5
|
|
|
5
|
-
def transform(language)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
def transform(language)
|
|
7
|
+
language
|
|
8
|
+
.to_resource_h
|
|
9
|
+
.replace_key!(:runner_url, :test_runner_url)
|
|
10
|
+
end
|
|
9
11
|
end
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
class Mumuki::Bibliotheca::App < Sinatra::Application
|
|
2
|
+
helpers do
|
|
3
|
+
def list_topics(topics)
|
|
4
|
+
{ topics: topics.as_json(only: [:name, :slug]) }
|
|
5
|
+
end
|
|
4
6
|
end
|
|
5
|
-
end
|
|
6
7
|
|
|
7
|
-
get '/topics' do
|
|
8
|
-
|
|
9
|
-
end
|
|
8
|
+
get '/topics' do
|
|
9
|
+
list_topics Topic.all
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
get '/topics/writable' do
|
|
12
|
-
|
|
13
|
-
end
|
|
12
|
+
get '/topics/writable' do
|
|
13
|
+
list_topics Topic.allowed(current_user.permissions)
|
|
14
|
+
end
|
|
14
15
|
|
|
15
|
-
get '/topics/:organization/:repository' do
|
|
16
|
-
|
|
17
|
-
end
|
|
16
|
+
get '/topics/:organization/:repository' do
|
|
17
|
+
Topic.find_by_slug!(slug.to_s).to_resource_h
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
post '/topics' do
|
|
20
|
-
|
|
21
|
-
end
|
|
20
|
+
post '/topics' do
|
|
21
|
+
upsert! :topic
|
|
22
|
+
end
|
|
22
23
|
|
|
23
|
-
post '/book/:organization/:repository/fork' do
|
|
24
|
-
|
|
25
|
-
end
|
|
24
|
+
post '/book/:organization/:repository/fork' do
|
|
25
|
+
fork! Topic
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
delete '/topics/:organization/:repository' do
|
|
28
|
-
|
|
28
|
+
delete '/topics/:organization/:repository' do
|
|
29
|
+
delete! Topic
|
|
30
|
+
end
|
|
29
31
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require 'sinatra'
|
|
1
|
+
require 'sinatra/base'
|
|
2
2
|
require 'mumukit/content_type'
|
|
3
3
|
|
|
4
4
|
require 'sinatra/cross_origin'
|
|
@@ -8,167 +8,168 @@ require 'mumukit/auth'
|
|
|
8
8
|
require 'json'
|
|
9
9
|
require 'yaml'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
class Mumuki::Bibliotheca::App < Sinatra::Application
|
|
12
|
+
configure do
|
|
13
|
+
enable :cross_origin
|
|
14
|
+
set :allow_methods, [:get, :put, :post, :options, :delete]
|
|
15
|
+
set :show_exceptions, false
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
set :app_name, 'bibliotheca'
|
|
18
|
+
set :static, true
|
|
19
|
+
set :public_folder, 'public'
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
helpers do
|
|
24
|
-
def json_body
|
|
25
|
-
@json_body ||= JSON.parse(request.body.read) rescue nil
|
|
21
|
+
use ::Rack::CommonLogger, Rails.logger
|
|
26
22
|
end
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
elsif subject
|
|
32
|
-
Mumukit::Auth::Slug.parse(subject.slug)
|
|
33
|
-
elsif json_body
|
|
34
|
-
Mumukit::Auth::Slug.parse(json_body['slug'])
|
|
35
|
-
else
|
|
36
|
-
raise Mumukit::Auth::InvalidSlugFormatError.new('Slug not available')
|
|
24
|
+
helpers do
|
|
25
|
+
def json_body
|
|
26
|
+
@json_body ||= JSON.parse(request.body.read) rescue nil
|
|
37
27
|
end
|
|
38
|
-
end
|
|
39
28
|
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
def slug
|
|
30
|
+
if route_slug_parts.present?
|
|
31
|
+
Mumukit::Auth::Slug.join(*route_slug_parts)
|
|
32
|
+
elsif subject
|
|
33
|
+
Mumukit::Auth::Slug.parse(subject.slug)
|
|
34
|
+
elsif json_body
|
|
35
|
+
Mumukit::Auth::Slug.parse(json_body['slug'])
|
|
36
|
+
else
|
|
37
|
+
raise Mumukit::Auth::InvalidSlugFormatError.new('Slug not available')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def route_slug_parts
|
|
42
|
+
[]
|
|
43
|
+
end
|
|
42
44
|
end
|
|
43
|
-
end
|
|
44
45
|
|
|
45
|
-
before do
|
|
46
|
-
|
|
47
|
-
end
|
|
46
|
+
before do
|
|
47
|
+
content_type 'application/json', 'charset' => 'utf-8'
|
|
48
|
+
end
|
|
48
49
|
|
|
49
|
-
after do
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
after do
|
|
51
|
+
error_message = env['sinatra.error']
|
|
52
|
+
if response.body.is_a?(Array)&& response.body[0].is_a?(String)
|
|
53
|
+
if content_type != 'application/csv'
|
|
54
|
+
content_type 'text/html'
|
|
55
|
+
response.body[0] = <<HTML
|
|
55
56
|
<html>
|
|
56
57
|
<body>
|
|
57
58
|
#{response.body[0]}
|
|
58
59
|
</body>
|
|
59
60
|
</html>
|
|
60
61
|
HTML
|
|
62
|
+
end
|
|
63
|
+
response.body = response.body[0]
|
|
64
|
+
elsif error_message.blank?
|
|
65
|
+
response.body = response.body.to_json
|
|
66
|
+
else
|
|
67
|
+
response.body = {message: env['sinatra.error'].message}.to_json
|
|
61
68
|
end
|
|
62
|
-
response.body = response.body[0]
|
|
63
|
-
elsif error_message.blank?
|
|
64
|
-
response.body = response.body.to_json
|
|
65
|
-
else
|
|
66
|
-
response.body = {message: env['sinatra.error'].message}.to_json
|
|
67
69
|
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
error JSON::ParserError do
|
|
71
|
-
halt 400
|
|
72
|
-
end
|
|
73
70
|
|
|
74
|
-
error
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
error Mumukit::Auth::UnauthorizedAccessError do
|
|
79
|
-
halt 403
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
error ActiveRecord::RecordInvalid do
|
|
83
|
-
halt 400
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
error Mumukit::Auth::InvalidSlugFormatError do
|
|
87
|
-
halt 400
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
error ActiveRecord::RecordNotFound do
|
|
91
|
-
halt 404
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
options '*' do
|
|
95
|
-
response.headers['Allow'] = settings.allow_methods.map { |it| it.to_s.upcase }.join(',')
|
|
96
|
-
response.headers['Access-Control-Allow-Headers'] = 'X-Mumuki-Auth-Token, X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept, Authorization'
|
|
97
|
-
200
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
helpers do
|
|
101
|
-
Mumukit::Login.configure_controller! self
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
before do
|
|
105
|
-
I18n.locale = 'en' #TODO: Remove hardcoded locale
|
|
106
|
-
end
|
|
71
|
+
error JSON::ParserError do
|
|
72
|
+
halt 400
|
|
73
|
+
end
|
|
107
74
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
halt 401 unless current_user?
|
|
75
|
+
error Mumukit::Auth::InvalidTokenError do
|
|
76
|
+
halt 401
|
|
111
77
|
end
|
|
112
78
|
|
|
113
|
-
|
|
114
|
-
|
|
79
|
+
error Mumukit::Auth::UnauthorizedAccessError do
|
|
80
|
+
halt 403
|
|
115
81
|
end
|
|
116
82
|
|
|
117
|
-
|
|
118
|
-
|
|
83
|
+
error ActiveRecord::RecordInvalid do
|
|
84
|
+
halt 400
|
|
119
85
|
end
|
|
120
86
|
|
|
121
|
-
|
|
122
|
-
|
|
87
|
+
error Mumukit::Auth::InvalidSlugFormatError do
|
|
88
|
+
halt 400
|
|
123
89
|
end
|
|
124
90
|
|
|
125
|
-
|
|
126
|
-
|
|
91
|
+
error ActiveRecord::RecordNotFound do
|
|
92
|
+
halt 404
|
|
127
93
|
end
|
|
128
94
|
|
|
129
|
-
|
|
130
|
-
|
|
95
|
+
options '*' do
|
|
96
|
+
response.headers['Allow'] = settings.allow_methods.map { |it| it.to_s.upcase }.join(',')
|
|
97
|
+
response.headers['Access-Control-Allow-Headers'] = 'X-Mumuki-Auth-Token, X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept, Authorization'
|
|
98
|
+
200
|
|
131
99
|
end
|
|
132
100
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
content = api_syncer.locate_and_import! content_kind, slug.to_s
|
|
136
|
-
history_syncer.export! content
|
|
137
|
-
content.to_resource_h
|
|
101
|
+
helpers do
|
|
102
|
+
Mumukit::Login.configure_controller! self
|
|
138
103
|
end
|
|
139
104
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
destination = json_body['organization']
|
|
143
|
-
collection_class.find_by_slug!(slug.to_s).fork_to!(destination, history_syncer).as_json
|
|
105
|
+
before do
|
|
106
|
+
I18n.locale = 'en' #TODO: Remove hardcoded locale
|
|
144
107
|
end
|
|
145
108
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
109
|
+
helpers do
|
|
110
|
+
def authenticate!
|
|
111
|
+
halt 401 unless current_user?
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def authorization_slug
|
|
115
|
+
slug
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def subject
|
|
119
|
+
Guide.find_by_id(params[:id])
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def route_slug_parts
|
|
123
|
+
[params[:organization], params[:repository]].compact
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def history_syncer
|
|
127
|
+
Mumuki::Bibliotheca.history_syncer(current_user)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def api_syncer
|
|
131
|
+
Mumuki::Bibliotheca.api_syncer(json_body)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def upsert!(content_kind)
|
|
135
|
+
authorize! :writer
|
|
136
|
+
content = api_syncer.locate_and_import! content_kind, slug.to_s
|
|
137
|
+
history_syncer.export! content
|
|
138
|
+
content.to_resource_h
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def fork!(collection_class)
|
|
142
|
+
authorize! :writer
|
|
143
|
+
destination = json_body['organization']
|
|
144
|
+
collection_class.find_by_slug!(slug.to_s).fork_to!(destination, history_syncer).as_json
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def delete!(collection_class)
|
|
148
|
+
authorize! :editor
|
|
149
|
+
collection_class.find_by_slug!(slug.to_s).destroy!
|
|
150
|
+
{}
|
|
151
|
+
end
|
|
150
152
|
end
|
|
151
|
-
end
|
|
152
153
|
|
|
153
|
-
post '/markdown' do
|
|
154
|
-
|
|
155
|
-
end
|
|
154
|
+
post '/markdown' do
|
|
155
|
+
{markdown: Mumukit::ContentType::Markdown.to_html(json_body['markdown'])}
|
|
156
|
+
end
|
|
156
157
|
|
|
157
|
-
post '/markdowns' do
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
post '/markdowns' do
|
|
159
|
+
json_body.with_indifferent_access.tap do |guide|
|
|
160
|
+
guide[:exercises].each do |exercise|
|
|
161
|
+
exercise[:description] = Mumukit::ContentType::Markdown.to_html(exercise[:description])
|
|
162
|
+
end
|
|
161
163
|
end
|
|
162
164
|
end
|
|
163
|
-
end
|
|
164
165
|
|
|
165
|
-
get '/permissions' do
|
|
166
|
-
|
|
166
|
+
get '/permissions' do
|
|
167
|
+
authenticate!
|
|
167
168
|
|
|
168
|
-
|
|
169
|
+
{permissions: current_user.permissions}
|
|
170
|
+
end
|
|
169
171
|
end
|
|
170
172
|
|
|
171
|
-
|
|
172
173
|
require_relative './sinatra/organization'
|
|
173
174
|
require_relative './sinatra/languages'
|
|
174
175
|
require_relative './sinatra/guides'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mumuki-bibliotheca
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Franco Bulgarelli
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -24,20 +24,34 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 5.1.6
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: sinatra
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.0'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: sinatra-contrib
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
30
44
|
requirements:
|
|
31
|
-
- - "
|
|
45
|
+
- - "~>"
|
|
32
46
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
47
|
+
version: '2.0'
|
|
34
48
|
type: :runtime
|
|
35
49
|
prerelease: false
|
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
51
|
requirements:
|
|
38
|
-
- - "
|
|
52
|
+
- - "~>"
|
|
39
53
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
54
|
+
version: '2.0'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: sinatra-cross_origin
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,14 +72,14 @@ dependencies:
|
|
|
58
72
|
requirements:
|
|
59
73
|
- - "~>"
|
|
60
74
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 6.
|
|
75
|
+
version: 6.2.0
|
|
62
76
|
type: :runtime
|
|
63
77
|
prerelease: false
|
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
79
|
requirements:
|
|
66
80
|
- - "~>"
|
|
67
81
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 6.
|
|
82
|
+
version: 6.2.0
|
|
69
83
|
- !ruby/object:Gem::Dependency
|
|
70
84
|
name: mumukit-login
|
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -179,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
179
193
|
- !ruby/object:Gem::Version
|
|
180
194
|
version: '0'
|
|
181
195
|
requirements: []
|
|
182
|
-
|
|
183
|
-
rubygems_version: 2.7.8
|
|
196
|
+
rubygems_version: 3.0.0
|
|
184
197
|
signing_key:
|
|
185
198
|
specification_version: 4
|
|
186
199
|
summary: API for editing content on mumuki
|