aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2013-08-14 13:50:56 +0200
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2014-05-07 02:58:48 +0200
commit592d37d72f85037ce41ea58f9f930e608ec338f8 (patch)
tree7616c258d8925e4f1b5bb739e81053ec717e1dee
parentce1773461b71a40afb406f4148b32aad11b52a57 (diff)
downloadecs2-592d37d72f85037ce41ea58f9f930e608ec338f8.tar.gz
ecs2-592d37d72f85037ce41ea58f9f930e608ec338f8.zip
New resource /sys/configs
Every participant could GET and POST to this resource. A GET might show this: curl ... -H 'Content-Type: application/json' \ -X GET https://ecs.host.com/sys/configs { "participant_events": "true", "resource_events": { "/campusconnect/glossaries": true, "/campusconnect/course_urls": true, "/campusconnect/course_members": true, "/campusconnect/wikis": true, "/campusconnect/directory_trees": true, "/campusconnect/learningmodules": true, "/campusconnect/groups": true, "/campusconnect/categories": true, "/campusconnect/courselinks": true, "/campusconnect/organisation_units": true, "/campusconnect/files": true, "/campusconnect/terms": true, "/campusconnect/courses": true, "/sys/auths": false }, "selfrouting": "false" } Only if participant_events and the appropriate resource_events are true, you will get an event. It's also possible to set the two attributes participant_events and selfrouting. Just make a POST such as: curl ... -H 'Content-Type: application/json' -X -X POST \ -d '{"participant_events":true}' https://ecs.host.com/sys/configs or curl ... -H 'Content-Type: application/json' -X -X POST \ -d '{"selfrouting":false}' https://ecs.host.com/sys/configs or curl ... -H 'Content-Type: application/json' -X -X POST \ -d '{"selfrouting":false, "participant_events":true}' \ https://ecs.host.com/sys/configs As you see, just set the attribute you want to set and make a POST. You don't have to provide a receiver header, because the receiver is implicitely the ECS.
-rw-r--r--app/controllers/configs_controller.rb64
-rw-r--r--app/helpers/configs_helper.rb2
-rw-r--r--app/views/configs/create.html.erb2
-rw-r--r--app/views/configs/index.html.erb2
-rw-r--r--config/routes.rb2
-rw-r--r--test/functional/configs_controller_test.rb8
-rw-r--r--test/unit/helpers/configs_helper_test.rb4
7 files changed, 84 insertions, 0 deletions
diff --git a/app/controllers/configs_controller.rb b/app/controllers/configs_controller.rb
new file mode 100644
index 0000000..a6a12cb
--- /dev/null
+++ b/app/controllers/configs_controller.rb
@@ -0,0 +1,64 @@
+class ConfigsController < ApplicationController
+
+ require 'json/add/rails'
+
+ before_filter :authentication
+ before_filter :add_cookie_header # only for anonymous participants
+
+ def initialize
+ super
+ end
+
+ def index
+ config_render
+ end
+
+ def create
+ unless Mime::Type.lookup(request.headers["CONTENT_TYPE"]).to_sym == :json
+ raise Ecs::InvalidMimetypeException, "Please provide \"Content-Type:\" header. Data format has to be in JSON (application/json)"
+ end
+
+ config= ActiveSupport::JSON.decode request.raw_post
+
+ if config["participant_events"] == true
+ @participant.events_= true
+ else
+ @participant.events_= false
+ end unless config["participant_events"].nil?
+
+ if config["selfrouting"] == true
+ @participant.community_selfrouting= true
+ else
+ @participant.community_selfrouting= false
+ end unless config["selfrouting"].nil?
+
+ @participant.save!
+ config_render
+ #rescue ActiveSupport::OkJson::Error
+ rescue Ecs::InvalidMimetypeException
+ raise
+ rescue ActiveRecord::RecordInvalid
+ raise Ecs::InvalidMessageException, "Data could not be saved (ConfigsController#create)."
+ rescue StandardError
+ raise Ecs::InvalidMessageException, "You have provided invalid JSON data (ConfigsController#create)."
+ end
+
+private
+
+ def config_render
+ config = nil
+ config_txt = ""
+ res_ev={};Ressource.all.each {|r| res_ev["/#{r.namespace}/#{r.ressource}"] = r.events}
+ config= \
+ {
+ :participant_events => @participant.events?.to_s,
+ :resource_events => res_ev,
+ :selfrouting => @participant.community_selfrouting.to_s
+ }
+ respond_to do |format|
+ format.json { render :json => JSON.pretty_generate(config) + "\r\n" }
+ format.xml { render :xml => config }
+ end
+ end
+
+end
diff --git a/app/helpers/configs_helper.rb b/app/helpers/configs_helper.rb
new file mode 100644
index 0000000..5cac46f
--- /dev/null
+++ b/app/helpers/configs_helper.rb
@@ -0,0 +1,2 @@
+module ConfigsHelper
+end
diff --git a/app/views/configs/create.html.erb b/app/views/configs/create.html.erb
new file mode 100644
index 0000000..52a9380
--- /dev/null
+++ b/app/views/configs/create.html.erb
@@ -0,0 +1,2 @@
+<h1>Configs#create</h1>
+<p>Find me in app/views/configs/create.html.erb</p>
diff --git a/app/views/configs/index.html.erb b/app/views/configs/index.html.erb
new file mode 100644
index 0000000..df50741
--- /dev/null
+++ b/app/views/configs/index.html.erb
@@ -0,0 +1,2 @@
+<h1>Configs#index</h1>
+<p>Find me in app/views/configs/index.html.erb</p>
diff --git a/config/routes.rb b/config/routes.rb
index ff8114c..eeae969 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -32,6 +32,8 @@ ActionController::Routing::Routes.draw do |map|
:only => [:index]
map.resources :events, :path_prefix => '/sys', :name_prefix => 'sys_',
:only => [:index], :collection => { :fifo => [:get, :post] }
+ map.resources :configs, :path_prefix => '/sys', :name_prefix => 'sys_',
+ :only => [:index, :create]
begin
Ressource.all.each do |r|
diff --git a/test/functional/configs_controller_test.rb b/test/functional/configs_controller_test.rb
new file mode 100644
index 0000000..049e561
--- /dev/null
+++ b/test/functional/configs_controller_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ConfigsControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/test/unit/helpers/configs_helper_test.rb b/test/unit/helpers/configs_helper_test.rb
new file mode 100644
index 0000000..4a0c42a
--- /dev/null
+++ b/test/unit/helpers/configs_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ConfigsHelperTest < ActionView::TestCase
+end