1 # Update and read user preferences, which are arbitrayr key/val pairs
2 class UserPreferenceController < ApplicationController
3 before_filter :authorize
6 pref = UserPreference.find(:first, :conditions => ['user_id = ? AND k = ?', @user.id, params[:preference_key]])
9 render :text => pref.v.to_s
11 render :text => 'OH NOES! PREF NOT FOUND!', :status => 404
16 pref = UserPreference.find(:first, :conditions => ['user_id = ? AND k = ?', @user.id, params[:preference_key]])
19 pref.v = request.raw_post.chomp
22 pref = UserPreference.new
24 pref.k = params[:preference_key]
25 pref.v = request.raw_post.chomp
31 # print out all the preferences as a big xml block
33 doc = OSM::API.new.get_xml_doc
35 prefs = @user.preferences
37 el1 = XML::Node.new 'preferences'
40 el1 << pref.to_xml_node
44 render :text => doc.to_s, :content_type => "text/xml"
47 # update the entire set of preferences
51 p.string = request.raw_post
58 doc.find('//preferences/preference').each do |pt|
59 pref = UserPreference.new
61 unless keyhash[pt['k']].nil? # already have that key
62 render :text => 'OH NOES! CAN HAS UNIQUE KEYS?', :status => :not_acceptable
70 pref.user_id = @user.id
75 render :text => 'Too many preferences', :status => :request_entity_too_large
79 # kill the existing ones
80 UserPreference.delete_all(['user_id = ?', @user.id])
87 rescue Exception => ex
88 render :text => 'OH NOES! FAIL!: ' + ex.to_s, :status => :internal_server_error
92 render :nothing => true