mumuki-bibliotheca 6.2.2 → 6.4.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
  SHA256:
3
- metadata.gz: c49be8ab2a2941f9bb2c48cd13eff5da71860392c15991f358ce89ec488cdee0
4
- data.tar.gz: 54660a3c891a128a9284c32e38521c468a2bd3fda037dcaeef83c65c0626baad
3
+ metadata.gz: f154a0f7493c9b04b0f3c0e02491271e05760eb36deb8310575a2d8e97fae3b0
4
+ data.tar.gz: 17cbab22333dcacec4aab3d650a91925f5dbd7024b3ddb7321b7628c6be01740
5
5
  SHA512:
6
- metadata.gz: 74d17df501da0253d8b8cf23af42ab6c36971b8ddac92b955ad20f6c18d4dc50b5a0b1f9999a0247b7053960c48d63b4ddfff770884bcc33375e86e84cde89cd
7
- data.tar.gz: b8e8d51b6139d6a7cf0e1fd541d64a8d7ea3f9c81974c98a5104bede941d1f0a82b5a46a2fdc62ad3d81d4af2335be0c704dc8d71d82094463f8bfd5311c635c
6
+ metadata.gz: e59dc509afcd88bb86d461fdf4265479d50d45a54e4c6114882a1fddbc98bfd79d0c0d1e81008db3617b1dd623f799981b91d230d494d5ef028698348a9eb5aa
7
+ data.tar.gz: a56954abcc745f68b5e1b5bc6d6c118c4e4a2ea110a19723d7253f8e3060fb31e1e077ae5483a20ba230f700685201f20653bf7203cc8fe88400d2e488be4364
@@ -1,5 +1,9 @@
1
1
  class Mumuki::Bibliotheca::App < Sinatra::Application
2
2
  helpers do
3
+ def book
4
+ Book.find_by_slug! slug.to_s
5
+ end
6
+
3
7
  def list_books(books)
4
8
  { books: books.as_json(only: [:name, :slug, :chapters]) }
5
9
  end
@@ -10,14 +14,22 @@ class Mumuki::Bibliotheca::App < Sinatra::Application
10
14
  end
11
15
 
12
16
  get '/books/writable' do
13
- list_books Book.allowed(current_user.permissions)
17
+ list_books Book.allowed(permissions)
14
18
  end
15
19
 
16
20
  get '/books/:organization/:repository' do
17
- Book.find_by_slug!(slug.to_s).to_resource_h
21
+ book.to_resource_h
22
+ end
23
+
24
+ get '/books/:organization/:repository/organizations' do
25
+ organizations_for book
18
26
  end
19
27
 
20
28
  post '/books' do
29
+ insert_and_notify! :book
30
+ end
31
+
32
+ put'/books' do
21
33
  upsert_and_notify! :book
22
34
  end
23
35
 
@@ -1,5 +1,9 @@
1
1
  class Mumuki::Bibliotheca::App < Sinatra::Application
2
2
  helpers do
3
+ def guide
4
+ Guide.find_by_slug!(slug.to_s)
5
+ end
6
+
3
7
  def list_guides(guides)
4
8
  { guides: guides.map { |it| it.as_json(only: [:name, :slug, :type]).merge(language: it.language.name) } }
5
9
  end
@@ -22,14 +26,22 @@ class Mumuki::Bibliotheca::App < Sinatra::Application
22
26
  end
23
27
 
24
28
  get '/guides/:organization/:repository/markdown' do
25
- slice_guide_resource_h_for_api Guide.find_by_slug!(slug.to_s).to_markdownified_resource_h
29
+ slice_guide_resource_h_for_api guide.to_markdownified_resource_h
26
30
  end
27
31
 
28
32
  get '/guides/:organization/:repository' do
29
- slice_guide_resource_h_for_api Guide.find_by_slug!(slug.to_s).to_resource_h
33
+ slice_guide_resource_h_for_api guide.to_resource_h
34
+ end
35
+
36
+ get '/guides/:organization/:repository/organizations' do
37
+ organizations_for guide
30
38
  end
31
39
 
32
40
  post '/guides' do
41
+ insert_and_notify! :guide
42
+ end
43
+
44
+ put '/guides' do
33
45
  upsert_and_notify! :guide
34
46
  end
35
47
 
@@ -1,5 +1,9 @@
1
1
  class Mumuki::Bibliotheca::App < Sinatra::Application
2
2
  helpers do
3
+ def topic
4
+ Topic.find_by_slug!(slug.to_s)
5
+ end
6
+
3
7
  def list_topics(topics)
4
8
  { topics: topics.as_json(only: [:name, :slug]) }
5
9
  end
@@ -10,14 +14,22 @@ class Mumuki::Bibliotheca::App < Sinatra::Application
10
14
  end
11
15
 
12
16
  get '/topics/writable' do
13
- list_topics Topic.allowed(current_user.permissions)
17
+ list_topics Topic.allowed(permissions)
14
18
  end
15
19
 
16
20
  get '/topics/:organization/:repository' do
17
- Topic.find_by_slug!(slug.to_s).to_resource_h
21
+ topic.to_resource_h
22
+ end
23
+
24
+ get '/topics/:organization/:repository/organizations' do
25
+ organizations_for topic
18
26
  end
19
27
 
20
28
  post '/topics' do
29
+ insert_and_notify! :topic
30
+ end
31
+
32
+ put '/topics' do
21
33
  upsert_and_notify! :topic
22
34
  end
23
35
 
@@ -92,6 +92,10 @@ HTML
92
92
  halt 404
93
93
  end
94
94
 
95
+ error Mumukit::Sync::SyncError do
96
+ halt 400
97
+ end
98
+
95
99
  options '*' do
96
100
  response.headers['Allow'] = settings.allow_methods.map { |it| it.to_s.upcase }.join(',')
97
101
  response.headers['Access-Control-Allow-Headers'] = 'X-Mumuki-Auth-Token, X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept, Authorization'
@@ -131,6 +135,11 @@ HTML
131
135
  Mumuki::Bibliotheca.api_syncer(json_body)
132
136
  end
133
137
 
138
+ def insert_and_notify!(content_kind)
139
+ raise Mumukit::Auth::InvalidSlugFormatError, "#{content_kind.as_module_name} with slug #{slug} already exists!" if content_kind.as_module.find_by_slug(slug.to_s)
140
+ upsert_and_notify!(content_kind)
141
+ end
142
+
134
143
  def upsert_and_notify!(content_kind)
135
144
  resource_h = upsert! content_kind
136
145
 
@@ -156,6 +165,17 @@ HTML
156
165
  collection_class.find_by_slug!(slug.to_s).destroy!
157
166
  {}
158
167
  end
168
+
169
+ def permissions
170
+ current_user.permissions
171
+ end
172
+
173
+ def organizations_for(item)
174
+ Organization
175
+ .in_path(item)
176
+ .accessible_as(current_user, :student)
177
+ .map { |it| it.as_json(only: [:name]) }
178
+ end
159
179
  end
160
180
 
161
181
  post '/markdown' do
@@ -173,7 +193,7 @@ HTML
173
193
  get '/permissions' do
174
194
  authenticate!
175
195
 
176
- {permissions: current_user.permissions}
196
+ {permissions: permissions}
177
197
  end
178
198
  end
179
199
 
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Bibliotheca
3
- VERSION = '6.2.2'
3
+ VERSION = '6.4.0'
4
4
  end
5
5
  end
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.2.2
4
+ version: 6.4.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-12-27 00:00:00.000000000 Z
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 6.2.2
75
+ version: 6.4.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 6.2.2
82
+ version: 6.4.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mumukit-login
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.3'
117
+ version: '0.4'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.3'
124
+ version: '0.4'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rack
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -176,7 +176,7 @@ files:
176
176
  - lib/tasks/guides.rake
177
177
  homepage: https://mumuki.org
178
178
  licenses:
179
- - GPL-3.0
179
+ - AGPL-3.0
180
180
  metadata: {}
181
181
  post_install_message:
182
182
  rdoc_options: []
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  requirements: []
196
- rubygems_version: 3.0.1
196
+ rubygems_version: 3.0.2
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: API for editing content on mumuki