Files
mapknitter/app/controllers/application_controller.rb
Divya Baid b8757c16bc Version tracking of images (#862)
* version-1

* version-2

* code climate fix

* Change count to count_version

* Logged in users can edit the maps

* Test added

* clock button added

* clock button added history button removed

* Change papertrail version to json, set limit to 10

- Clean up revert method

* test image versioning and rollback

* remove version limit

* create temp image folders

* script removed

* Small change

* warpable saved

* Small fix

* version-revert fixed

* Cloned version added on top

* final changes

* final changes - 1

* Removing count_version

* tests improved

* remove byebug
2019-08-04 02:16:11 +05:30

64 lines
1.4 KiB
Ruby
Executable File

class ApplicationController < ActionController::Base
# include OpenIdAuthentication # shouldn't be necessary!!
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
helper :all # include all helpers, all the time
before_filter :current_user
helper_method :logged_in?, :current_location
before_action :set_paper_trail_whodunnit
def user_for_paper_trail
# Save the user responsible for the action
logged_in? ? current_user.id : 'Anonymous'
end
def current_user
user_id = session[:user_id]
if user_id
begin
@user = User.find(user_id)
rescue StandardError
@user = nil
end
else
@user = nil
end
end
private
def current_location
session[:lat].present? && session[:lon].present?
end
def require_login
unless logged_in?
path_info = request.env['PATH_INFO']
flash[:warning] = 'You must be logged in to access this section'
redirect_to '/login?back_to=' + path_info.to_param # halts request cycle
end
end
def logged_in?
user_id = session[:user_id]
begin
user_id && User.find(user_id) ? true : false
rescue StandardError
return false
end
end
def save_tags(map)
return unless params[:tags].present?
params[:tags].tr(' ', ',').split(',').each do |tagname|
map.add_tag(tagname.strip, current_user)
end
end
end