Files
mapknitter/app/controllers/application_controller.rb
Alicia Paz d2d45dbf42 Migrate from Travis to GitHub Actions for CI (#1534)
* Try migrating from Travis to GitHub Actions for CI

* Update actions.yml and tests.yml

* Add ruby version

* Update config/database.yml.example

* Try rubocop and docker jobs

* Fix indentation

* Update tests.yml

* Update tests.yml

* Update gemfile

* Update rubocop job and Gemfile

* Update .rubocop_shopify_styleguide.yml

* Update gemfile

* Update .rubocop_todo.yml

* Update rubocop configuration and styleguides

* Fix rubocop offenses

* Update .rubocop.yml

* Update .rubocop.yml

* Udate .codeclimate.yml

* Update .codeclimate.yml

* Update .codeclimate.yml

* Update .codeclimate.yml

* Setup unit tests

* Update find_verified_user method in connection.rb

* Add yarn cache and install to setup

* install exporter dependencies; gdal/imagemagick

* Introduce Gitpod to migration work (#1538)

* Add CORS headers (#1536)

* Create .gitpod.dockerfile

* Create .gitpod.yml

* Create database.yml.gitpod

* Update .gitpod.yml

* ruby 2.4.6 in gitpod.dockerfile

* Update .gitpod.yml

* Update database.yml.gitpod

Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>

* Install gdal and use egordm for yarn cache

* Delete unnecessary query and fix layout

* Run script with verbose output

* Try installing package in action.yml

* Setup controllers job

* Fix indentation

* Setup system tests job

* Setup docker development build job

* Fix identifiers

* Fix path to action.yml

* Update development dockerfile

* Setup docker production build job

* Update tests.yml

* Setup assets precompilation job

* Setup production environment

* Update tests.yml

* Update action.yml for production

* Try with test setup

* Remove action.yml for production

* Change names of jobs for friendliness and clarity

* Update .github/workflows/tests.yml

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>

* Move dockerfiles to directory and change docker job names for clarity

* Update docker job names

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
2021-09-20 18:50:31 -04:00

66 lines
1.5 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_action :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
u = User.find(user_id)
cookies.signed["user_id"] = u.id
@user = u
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
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