Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (57 sloc) 1.94 KB
#
# ixtlan_translations - webapp where you can manage translations of applications
# Copyright (C) 2012 Christian Meier
#
# This file is part of ixtlan_translations.
#
# ixtlan_translations is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ixtlan_translations is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with ixtlan_translations. If not, see <http://www.gnu.org/licenses/>.
#
class LocalController < ApplicationController
protect_from_forgery
protected
before_filter :cleanup
def updated_at(key = params[:controller])
@_updated_at ||= (params[key] || {})[:updated_at]
end
def cleanup(model = nil)
#TODO cleanup nested hashes
# compensate the shortcoming of the incoming json/xml
model ||= []
model.delete :id
model.delete :created_at
@_updated_at ||= model.delete :updated_at
end
private
after_filter :csrf
def csrf
response.header['X-CSRF-Token'] = form_authenticity_token
end
protected
def current_user(user = nil)
if user
session['user'] = serializer(user).use(:session).to_hash
@_current_user = user
else
@_current_user ||= begin
data = session['user']
if data
data = data.dup
u = User.get!(data['id'])
u.groups = data['groups'].collect { |g| Group.new( g.dup ) }
u
end
end
end
end
end