koda 0.0.8
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.
- data/lib/helpers/app_helper.rb +40 -0
- data/lib/helpers/koda_helper.rb +105 -0
- data/lib/helpers/view_helper.rb +146 -0
- data/lib/koda.rb +123 -0
- data/lib/models/hash.rb +29 -0
- data/lib/models/mongo_collection.rb +144 -0
- data/lib/models/mongo_config.rb +22 -0
- data/lib/models/mongo_database.rb +136 -0
- data/lib/models/mongo_document.rb +124 -0
- data/lib/models/mongo_grid.rb +85 -0
- data/lib/models/mongo_media.rb +55 -0
- data/lib/models/user_access_provider.rb +135 -0
- data/lib/models/user_context.rb +19 -0
- data/lib/routes/koda_api.rb +392 -0
- data/lib/routes/koda_site.rb +57 -0
- data/lib/views/console.erb +139 -0
- data/lib/views/explorer.erb +119 -0
- data/lib/views/login.erb +77 -0
- data/lib/views/not_allowed.erb +75 -0
- data/public/koda/Help/DataTypes.txt +82 -0
- data/public/koda/Help/KodaType_Template.js +48 -0
- data/public/koda/apple-touch-icon-114x114-precomposed.png +0 -0
- data/public/koda/apple-touch-icon-144x144-precomposed.png +0 -0
- data/public/koda/apple-touch-icon-57x57-precomposed.png +0 -0
- data/public/koda/apple-touch-icon-72x72-precomposed.png +0 -0
- data/public/koda/apple-touch-icon-precomposed.png +0 -0
- data/public/koda/apple-touch-icon.png +0 -0
- data/public/koda/css/bootstrap-responsive.css +1058 -0
- data/public/koda/css/bootstrap.css +5774 -0
- data/public/koda/css/main.css +288 -0
- data/public/koda/favicon.ico +0 -0
- data/public/koda/fonts/angelina-webfont.eot +0 -0
- data/public/koda/fonts/angelina-webfont.svg +228 -0
- data/public/koda/fonts/angelina-webfont.ttf +0 -0
- data/public/koda/fonts/angelina-webfont.woff +0 -0
- data/public/koda/fonts/coolvetica_rg-webfont.eot +0 -0
- data/public/koda/fonts/coolvetica_rg-webfont.svg +232 -0
- data/public/koda/fonts/coolvetica_rg-webfont.ttf +0 -0
- data/public/koda/fonts/coolvetica_rg-webfont.woff +0 -0
- data/public/koda/fonts/ladyic__-webfont.eot +0 -0
- data/public/koda/fonts/ladyic__-webfont.svg +257 -0
- data/public/koda/fonts/ladyic__-webfont.ttf +0 -0
- data/public/koda/fonts/ladyic__-webfont.woff +0 -0
- data/public/koda/images/ajax-loader.gif +0 -0
- data/public/koda/images/back.png +0 -0
- data/public/koda/images/bg-table-thead.png +0 -0
- data/public/koda/images/big_folder.png +0 -0
- data/public/koda/images/box_file.png +0 -0
- data/public/koda/images/car_add.png +0 -0
- data/public/koda/images/compress.png +0 -0
- data/public/koda/images/database_table.png +0 -0
- data/public/koda/images/feed_add.png +0 -0
- data/public/koda/images/feed_link.png +0 -0
- data/public/koda/images/file.png +0 -0
- data/public/koda/images/folder.png +0 -0
- data/public/koda/images/folder_image.png +0 -0
- data/public/koda/images/glyphicons-halflings-white.png +0 -0
- data/public/koda/images/glyphicons-halflings.png +0 -0
- data/public/koda/images/group_add.png +0 -0
- data/public/koda/images/group_key.png +0 -0
- data/public/koda/images/image_add.png +0 -0
- data/public/koda/images/layout_add.png +0 -0
- data/public/koda/images/package.png +0 -0
- data/public/koda/images/page_white_edit.png +0 -0
- data/public/koda/images/page_white_text.png +0 -0
- data/public/koda/images/photo_add.png +0 -0
- data/public/koda/images/toggle-collapse-dark.png +0 -0
- data/public/koda/images/toggle-collapse-light.png +0 -0
- data/public/koda/images/toggle-expand-dark.png +0 -0
- data/public/koda/images/toggle-expand-light.png +0 -0
- data/public/koda/images/twitter.png +0 -0
- data/public/koda/koda-editors/KodaEditor.js +843 -0
- data/public/koda/koda-editors/collection-editor.html +56 -0
- data/public/koda/koda-editors/generic-editor.css +112 -0
- data/public/koda/koda-editors/generic-editor.html +74 -0
- data/public/koda/koda-editors/koda-editor.css +72 -0
- data/public/koda/koda-editors/twitterfeed-editor.html +90 -0
- data/public/koda/koda-types/_builtin_registration.json +62 -0
- data/public/koda/koda-types/koda-access.json +49 -0
- data/public/koda/koda-types/koda-collection.json +12 -0
- data/public/koda/koda-types/koda-generictext.json +50 -0
- data/public/koda/koda-types/koda-media.json +58 -0
- data/public/koda/koda-types/koda-twitterfeed.json +79 -0
- data/public/koda/koda-types/koda-user.json +71 -0
- data/public/koda/nicEditorIcons.gif +0 -0
- data/public/koda/scripts/Koda.js +1200 -0
- data/public/koda/scripts/lib/DOMAssistant.js +4 -0
- data/public/koda/scripts/lib/modernizr.js +4 -0
- data/public/koda/scripts/lib/respond.js +2 -0
- data/public/koda/scripts/lib/selectivizr.js +5 -0
- data/public/koda/scripts/plugins/bootstrap.js +2027 -0
- data/public/koda/scripts/plugins/box.js +8 -0
- data/public/koda/scripts/plugins/fancybox/blank.gif +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_close.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_loading.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_nav_left.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_nav_right.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_e.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_n.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_ne.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_nw.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_s.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_se.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_sw.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_shadow_w.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_title_left.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_title_main.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_title_over.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancy_title_right.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancybox-x.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancybox-y.png +0 -0
- data/public/koda/scripts/plugins/fancybox/fancybox.png +0 -0
- data/public/koda/scripts/plugins/fancybox/jquery.easing-1.3.pack.js +72 -0
- data/public/koda/scripts/plugins/fancybox/jquery.fancybox-1.3.4.css +359 -0
- data/public/koda/scripts/plugins/fancybox/jquery.fancybox-1.3.4.js +1155 -0
- data/public/koda/scripts/plugins/fancybox/jquery.fancybox-1.3.4.pack.js +46 -0
- data/public/koda/scripts/plugins/fancybox/jquery.mousewheel-3.0.4.pack.js +14 -0
- data/public/koda/scripts/plugins/fileuploader.js +1527 -0
- data/public/koda/scripts/plugins/jquery-class.js +7 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/images/cut.png +0 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/images/door.png +0 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_copy.png +0 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_delete.png +0 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_edit.png +0 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/images/page_white_paste.png +0 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/jquery.contextMenu.css +63 -0
- data/public/koda/scripts/plugins/jquery.contextmenu/jquery.contextMenu.js +211 -0
- data/public/koda/scripts/plugins/jquery.js +2 -0
- data/public/koda/scripts/plugins/json2.js +277 -0
- data/public/koda/scripts/plugins/modernizr.js +2 -0
- data/public/koda/scripts/plugins/nicEdit.js +183 -0
- data/public/koda/scripts/plugins/qunit.js +1448 -0
- data/public/koda/scripts/plugins/spin.js +2 -0
- data/public/koda/scripts/plugins/uploader/README.md +77 -0
- data/public/koda/scripts/plugins/uploader/README.txt +89 -0
- data/public/koda/scripts/plugins/uploader/example/application.js +20 -0
- data/public/koda/scripts/plugins/uploader/example/index.html +109 -0
- data/public/koda/scripts/plugins/uploader/example/style.css +22 -0
- data/public/koda/scripts/plugins/uploader/example/upload.php +313 -0
- data/public/koda/scripts/plugins/uploader/jquery.fileupload-ui.css +100 -0
- data/public/koda/scripts/plugins/uploader/jquery.fileupload-ui.js +642 -0
- data/public/koda/scripts/plugins/uploader/jquery.fileupload.js +711 -0
- data/public/koda/scripts/plugins/uploader/jquery.iframe-transport.js +133 -0
- data/public/koda/scripts/plugins/uploader/pbar-ani.gif +0 -0
- data/public/koda/scripts/plugins/uploader/tests/index.html +115 -0
- data/public/koda/scripts/plugins/uploader/tests/tests.js +1008 -0
- data/public/koda/scripts/require.js +32 -0
- data/public/koda/scripts/specs.js +12 -0
- data/public/koda/scripts/specs/cd-command-spec.js +51 -0
- data/public/koda/scripts/specs/controller-spec.js +95 -0
- data/public/koda/scripts/specs/doubles/mock-command.js +21 -0
- data/public/koda/scripts/specs/doubles/mock-jamservice.js +33 -0
- data/public/koda/scripts/specs/doubles/mock-prompt.js +30 -0
- data/public/koda/scripts/specs/doubles/uiobject-double.js +15 -0
- data/public/koda/scripts/specs/edit-command-spec.js +76 -0
- data/public/koda/scripts/specs/ls-command-spec.js +61 -0
- data/public/koda/scripts/specs/mkdir-command-spec.js +40 -0
- data/public/koda/scripts/specs/peek-command-spec.js +24 -0
- data/public/koda/scripts/specs/remove-command-spec.js +37 -0
- data/public/koda/scripts/specs/service-spec.js +85 -0
- metadata +402 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class UserContext
|
|
2
|
+
|
|
3
|
+
def self.user_bag
|
|
4
|
+
@@user_bag
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.user_bag=(value)
|
|
8
|
+
@@user_bag = value
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.current_user
|
|
12
|
+
@@user_bag['koda_user']
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.current_user=(value)
|
|
16
|
+
@@user_bag['koda_user'] = value
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
get '/koda/*' do
|
|
2
|
+
response['Allow'] = 'GET'
|
|
3
|
+
path = File.dirname(__FILE__) + '/../../public' + request.path
|
|
4
|
+
response['Content-Type'] = 'text/css' if path =~ /.css$/
|
|
5
|
+
response['Content-Type'] = 'text/javascript' if path =~ /.js$/
|
|
6
|
+
response['Content-Type'] = 'image/jpeg' if path =~ /.jpg$/
|
|
7
|
+
response['Content-Type'] = 'image/png' if path =~ /.png$/
|
|
8
|
+
response['Content-Type'] = 'image/gif' if path =~ /.gif/
|
|
9
|
+
response['Content-Type'] = 'text/html' if path =~ /.html/
|
|
10
|
+
File.open(path, 'rb') {|f| f.read}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
get '/api' do
|
|
14
|
+
if(logged_in?)
|
|
15
|
+
content_type :json, 'kodameta' => 'list'
|
|
16
|
+
JSONP @db_wrapper.collection_links current_user
|
|
17
|
+
else
|
|
18
|
+
status 405
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
get '/api/' do
|
|
23
|
+
if(logged_in?)
|
|
24
|
+
content_type :json, 'kodameta' => 'list'
|
|
25
|
+
JSONP @db_wrapper.collection_links current_user
|
|
26
|
+
else
|
|
27
|
+
status 405
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
put '/api' do
|
|
32
|
+
status 405
|
|
33
|
+
response['Allow'] = 'GET'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
post '/api' do
|
|
37
|
+
response['Allow'] = 'GET'
|
|
38
|
+
status 405
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
delete '/api' do
|
|
42
|
+
response['Allow'] = 'GET'
|
|
43
|
+
status 405
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
options '/api' do
|
|
47
|
+
response['Allow'] = 'GET'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
put '/api' do
|
|
51
|
+
status 405
|
|
52
|
+
response['Allow'] = 'GET,POST'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
get '/session/current_user' do
|
|
56
|
+
if(logged_in?)
|
|
57
|
+
JSONP current_user
|
|
58
|
+
else
|
|
59
|
+
response['Allow'] = 'GET'
|
|
60
|
+
status 405
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#
|
|
65
|
+
# Media
|
|
66
|
+
#
|
|
67
|
+
get '/api/_koda_media/?' do
|
|
68
|
+
content_type :json, 'kodameta' => 'list'
|
|
69
|
+
media = @grid_wrapper.media_links.to_json
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
post '/api/_koda_media/?' do
|
|
73
|
+
|
|
74
|
+
if(logged_in?)
|
|
75
|
+
media = MongoMedia.new request, params
|
|
76
|
+
file_name = @grid_wrapper.save_media media
|
|
77
|
+
|
|
78
|
+
new_location = '/content/media/' + file_name
|
|
79
|
+
response['Location'] = new_location
|
|
80
|
+
status 200
|
|
81
|
+
result = {
|
|
82
|
+
'success' => 'true',
|
|
83
|
+
'location' => new_location,
|
|
84
|
+
}
|
|
85
|
+
body result.to_json
|
|
86
|
+
else
|
|
87
|
+
response['Allow'] = 'GET'
|
|
88
|
+
status 405
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
delete '/api/_koda_media/?' do
|
|
94
|
+
response['Allow'] = 'GET,POST'
|
|
95
|
+
status 405
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
options '/api/_koda_media/?' do
|
|
99
|
+
response['Allow'] = 'GET,POST'
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
get '/content/media/:filename' do
|
|
103
|
+
media = @grid_wrapper.get_media params[:filename]
|
|
104
|
+
|
|
105
|
+
if (media == nil)
|
|
106
|
+
halt 404
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
last_modified(media.last_updated)
|
|
110
|
+
|
|
111
|
+
content_type media.content_type
|
|
112
|
+
body media.body
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
get '/api/_koda_media/:filename' do
|
|
116
|
+
media = @grid_wrapper.get_media params[:filename]
|
|
117
|
+
|
|
118
|
+
if (media == nil)
|
|
119
|
+
halt 404
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
last_modified(media.last_updated)
|
|
123
|
+
|
|
124
|
+
content_type media.content_type
|
|
125
|
+
body media.body
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
put '/api/_koda_media/:filename?' do
|
|
129
|
+
|
|
130
|
+
if(logged_in?)
|
|
131
|
+
media = MongoMedia.new request, params
|
|
132
|
+
file_name = @grid_wrapper.save_media(media, params[:filename])
|
|
133
|
+
|
|
134
|
+
new_location = '/api/_koda_media/' + file_name
|
|
135
|
+
|
|
136
|
+
response['Location'] = new_location
|
|
137
|
+
status 200
|
|
138
|
+
result = {
|
|
139
|
+
'success' => 'true',
|
|
140
|
+
'location' => new_location,
|
|
141
|
+
}
|
|
142
|
+
body result.to_json
|
|
143
|
+
else
|
|
144
|
+
response['Allow'] = 'GET'
|
|
145
|
+
status 405
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
post '/api/_koda_media/:filename?' do
|
|
151
|
+
response['Allow'] = 'GET,PUT,DELETE'
|
|
152
|
+
status 405
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
delete '/api/_koda_media/:filename?' do
|
|
156
|
+
if(logged_in?)
|
|
157
|
+
@grid_wrapper.delete_media(params[:filename])
|
|
158
|
+
else
|
|
159
|
+
response['Allow'] = 'GET'
|
|
160
|
+
status 405
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
options '/api/_koda_media/:filename' do
|
|
165
|
+
media = @grid_wrapper.get_media params[:filename]
|
|
166
|
+
|
|
167
|
+
if (media == nil)
|
|
168
|
+
response['Allow'] = 'PUT'
|
|
169
|
+
return
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
response['Allow'] = 'GET,PUT,DELETE'
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
#
|
|
176
|
+
# Content
|
|
177
|
+
#
|
|
178
|
+
|
|
179
|
+
get '/content?' do
|
|
180
|
+
content_type :json, 'kodameta' => 'list'
|
|
181
|
+
JSONP @db_wrapper.content_collection_links
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
get '/content/?' do
|
|
185
|
+
content_type :json, 'kodameta' => 'list'
|
|
186
|
+
JSONP @db_wrapper.content_collection_links
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
get '/content/search/?' do
|
|
190
|
+
content_type :json, 'kodameta' => 'list'
|
|
191
|
+
JSONP create_content
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
get '/content/search/:collection/?' do
|
|
195
|
+
content_type :json, 'kodameta' => 'list'
|
|
196
|
+
collection_name = params[:collection]
|
|
197
|
+
JSONP @db_wrapper.search params,collection_name
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
get '/content/:collection/?' do
|
|
201
|
+
content_type :json, 'kodameta' => 'list'
|
|
202
|
+
collection_name = params[:collection]
|
|
203
|
+
|
|
204
|
+
sort = [['datecreated', Mongo::DESCENDING]]
|
|
205
|
+
|
|
206
|
+
if(is_public_read? collection_name)
|
|
207
|
+
halt 404 if not @db_wrapper.contains_collection(collection_name)
|
|
208
|
+
JSONP @db_wrapper.collection(collection_name).content_links(params[:take], params[:skip], sort)
|
|
209
|
+
else
|
|
210
|
+
response['Allow'] = 'GET'
|
|
211
|
+
status 405
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
get '/content/:collection/:resource?' do
|
|
217
|
+
|
|
218
|
+
collection_name = params[:collection]
|
|
219
|
+
doc_ref = params[:resource]
|
|
220
|
+
|
|
221
|
+
if(is_public_read? collection_name)
|
|
222
|
+
should_include = params[:include] != 'false'
|
|
223
|
+
|
|
224
|
+
doc = @db_wrapper.collection(collection_name).find_document(doc_ref)
|
|
225
|
+
halt 404 if doc==nil
|
|
226
|
+
last_modified(doc.last_modified)
|
|
227
|
+
|
|
228
|
+
fetch_linked_docs doc if should_include
|
|
229
|
+
|
|
230
|
+
JSONP doc.stripped_document
|
|
231
|
+
else
|
|
232
|
+
response['Allow'] = 'GET'
|
|
233
|
+
status 405
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
#
|
|
239
|
+
# Collections
|
|
240
|
+
#
|
|
241
|
+
|
|
242
|
+
get '/api/:collection/?' do
|
|
243
|
+
collection_name = params[:collection]
|
|
244
|
+
|
|
245
|
+
if(is_allowed? :read, collection_name)
|
|
246
|
+
|
|
247
|
+
halt 404 if not @db_wrapper.contains_collection(collection_name)
|
|
248
|
+
content_type :json, 'kodameta' => 'list'
|
|
249
|
+
|
|
250
|
+
sort = [['datecreated', Mongo::DESCENDING]]
|
|
251
|
+
|
|
252
|
+
if(is_admin?)
|
|
253
|
+
JSONP @db_wrapper.collection(collection_name).resource_links(params[:take], params[:skip], sort)
|
|
254
|
+
else
|
|
255
|
+
JSONP @db_wrapper.collection(collection_name).resource_links_no_hidden(params[:take], params[:skip], sort)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
else
|
|
259
|
+
status 405
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
post '/api/:collection/?' do
|
|
264
|
+
collection_name = params[:collection]
|
|
265
|
+
|
|
266
|
+
if(is_allowed? :write , collection_name)
|
|
267
|
+
raw_doc = request.env["rack.input"].read
|
|
268
|
+
hash = JSON.parse raw_doc
|
|
269
|
+
new_doc = @db_wrapper.collection(collection_name).save_document(hash)
|
|
270
|
+
refresh_cache
|
|
271
|
+
response['Location'] = new_doc.url
|
|
272
|
+
status 201
|
|
273
|
+
result = {
|
|
274
|
+
'success' => 'true',
|
|
275
|
+
'location' => new_doc.url
|
|
276
|
+
}
|
|
277
|
+
body new_doc.url
|
|
278
|
+
else
|
|
279
|
+
response['Allow'] = 'GET'
|
|
280
|
+
status 405
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
put '/api/:collection/?' do
|
|
285
|
+
status 405
|
|
286
|
+
response['Allow'] = 'GET,POST,DELETE'
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
delete '/api/:collection/?' do
|
|
290
|
+
collection_name = params[:collection]
|
|
291
|
+
|
|
292
|
+
if(is_allowed? :modify, collection_name)
|
|
293
|
+
@db_wrapper.collection(collection_name).delete()
|
|
294
|
+
else
|
|
295
|
+
response['Allow'] = 'GET'
|
|
296
|
+
status 405
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
options '/api/:collection/?' do
|
|
301
|
+
halt 404 if not @db_wrapper.contains_collection(params[:collection])
|
|
302
|
+
response['Allow'] = 'GET,POST,DELETE'
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
#
|
|
306
|
+
# Resources
|
|
307
|
+
#
|
|
308
|
+
|
|
309
|
+
get '/api/:collection/:resource?' do
|
|
310
|
+
collection_name = params[:collection]
|
|
311
|
+
|
|
312
|
+
if(is_allowed? :read, collection_name)
|
|
313
|
+
doc_ref = params[:resource]
|
|
314
|
+
should_include = params[:include] != 'false'
|
|
315
|
+
|
|
316
|
+
doc = @db_wrapper.collection(collection_name).find_document(doc_ref)
|
|
317
|
+
halt 404 if doc==nil
|
|
318
|
+
last_modified(doc.last_modified)
|
|
319
|
+
|
|
320
|
+
fetch_linked_docs doc if should_include
|
|
321
|
+
|
|
322
|
+
JSONP doc.standardised_document
|
|
323
|
+
else
|
|
324
|
+
response['Allow'] = 'GET'
|
|
325
|
+
status 405
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
post '/api/:collection/:resource' do
|
|
330
|
+
status 405
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
put '/api/:collection/:resource' do
|
|
334
|
+
collection_name = params[:collection]
|
|
335
|
+
|
|
336
|
+
if(is_allowed? :write, collection_name)
|
|
337
|
+
resource_name = params[:resource]
|
|
338
|
+
hash = JSON.parse request.env["rack.input"].read
|
|
339
|
+
|
|
340
|
+
if(hash['linked_documents'] != nil)
|
|
341
|
+
hash.delete 'linked_documents'
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
doc = @db_wrapper.collection(collection_name).save_document(hash, resource_name)
|
|
345
|
+
|
|
346
|
+
refresh_cache
|
|
347
|
+
|
|
348
|
+
status 201 if doc.is_new
|
|
349
|
+
|
|
350
|
+
response['Location'] = doc.url
|
|
351
|
+
|
|
352
|
+
body doc.url
|
|
353
|
+
else
|
|
354
|
+
response['Allow'] = 'GET'
|
|
355
|
+
status 405
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
delete '/api/:collection/:resource' do
|
|
360
|
+
collection_name = params[:collection]
|
|
361
|
+
|
|
362
|
+
if(is_allowed? :modify,collection_name)
|
|
363
|
+
@db_wrapper.collection(collection_name).delete_document(params[:resource])
|
|
364
|
+
else
|
|
365
|
+
response['Allow'] = 'GET'
|
|
366
|
+
status 405
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
options '/api/:collection/:resource' do
|
|
371
|
+
collection_name = params[:collection]
|
|
372
|
+
|
|
373
|
+
if(is_allowed? :read, collection_name)
|
|
374
|
+
doc_ref = params[:resource]
|
|
375
|
+
|
|
376
|
+
doc = @db_wrapper.collection(collection_name).find_document(doc_ref)
|
|
377
|
+
|
|
378
|
+
if (doc==nil)
|
|
379
|
+
response['Allow'] = 'PUT'
|
|
380
|
+
return
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
response['Allow'] = 'GET,PUT,DELETE'
|
|
384
|
+
else
|
|
385
|
+
response['Allow'] = 'GET'
|
|
386
|
+
status 405
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
options '*' do
|
|
392
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#
|
|
2
|
+
# MODIFY THESE IF YOU WANT A DIFFERENT LOGIN STRATEGY
|
|
3
|
+
#
|
|
4
|
+
get '/console' do
|
|
5
|
+
if(logged_in?)
|
|
6
|
+
if(is_allowed_in_console?)
|
|
7
|
+
show_system :console
|
|
8
|
+
else
|
|
9
|
+
redirect "/access-denied-console"
|
|
10
|
+
end
|
|
11
|
+
else
|
|
12
|
+
session['return_url'] = '/console'
|
|
13
|
+
redirect '/sign-in'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
get '/explorer' do
|
|
18
|
+
if(logged_in?)
|
|
19
|
+
if(is_allowed_in_explorer?)
|
|
20
|
+
show_system :explorer
|
|
21
|
+
else
|
|
22
|
+
redirect "/access-denied-explorer"
|
|
23
|
+
end
|
|
24
|
+
else
|
|
25
|
+
session['return_url'] = '/explorer'
|
|
26
|
+
redirect '/sign-in'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
get "/sign-in" do
|
|
31
|
+
show_system :login
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
get "/sign-out" do
|
|
35
|
+
log_out
|
|
36
|
+
redirect '/'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
get "/access-denied-console" do
|
|
40
|
+
@title = "Access denied"
|
|
41
|
+
@message = 'You need to be an administrator to access the console.'
|
|
42
|
+
show_system :not_allowed
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
get "/access-denied-explorer" do
|
|
46
|
+
@title = "Access denied"
|
|
47
|
+
@message = 'If you have just registered, you will be able to gain access as soon as an administrator approves you.'
|
|
48
|
+
show_system :not_allowed
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
post "/signed-in" do
|
|
52
|
+
if @uap.authenticate(params[:token])
|
|
53
|
+
redirect session['return_url']
|
|
54
|
+
else
|
|
55
|
+
redirect "/sign-in"
|
|
56
|
+
end
|
|
57
|
+
end
|