mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-05 16:00:00 +01:00
* 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>
91 lines
3.3 KiB
Ruby
91 lines
3.3 KiB
Ruby
module UsersHelper
|
|
#
|
|
# Use this to wrap view elements that the user can't access.
|
|
# !! Note: this is an *interface*, not *security* feature !!
|
|
# You need to do all access control at the controller level.
|
|
#
|
|
# Example:
|
|
# <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> |
|
|
# <%= if_authorized?(:edit, @user) do link_to('Edit this user', edit_user_path) end %> |
|
|
# <%= if_authorized?(:destroy, @user) do link_to 'Destroy', @user, :confirm => 'Are you sure?', :method => :delete end %>
|
|
#
|
|
#
|
|
def if_authorized?(action, resource)
|
|
yield(action, resource) if authorized?(action, resource)
|
|
end
|
|
|
|
#
|
|
# Link to user's page ('users/1')
|
|
#
|
|
# By default, their login is used as link text and link title (tooltip)
|
|
#
|
|
# Takes options
|
|
# * :content_text => 'Content text in place of user.login', escaped with
|
|
# the standard h() function.
|
|
# * :content_method => :user_instance_method_to_call_for_content_text
|
|
# * :title_method => :user_instance_method_to_call_for_title_attribute
|
|
# * as well as link_to()'s standard options
|
|
#
|
|
# Examples:
|
|
# link_to_user @user
|
|
# # => <a href="/users/3" title="barmy">barmy</a>
|
|
#
|
|
# # if you've added a .name attribute:
|
|
# content_tag :span, :class => :vcard do
|
|
# (link_to_user user, :class => 'fn n', :title_method => :login, :content_method => :name) +
|
|
# ': ' + (content_tag :span, user.email, :class => 'email')
|
|
# end
|
|
# # => <span class="vcard"><a href="/users/3" title="barmy" class="fn n">Cyril Fotheringay-Phipps</a>: <span class="email">barmy@blandings.com</span></span>
|
|
#
|
|
# link_to_user @user, :content_text => 'Your user page'
|
|
# # => <a href="/users/3" title="barmy" class="nickname">Your user page</a>
|
|
#
|
|
def link_to_user(user, options = {})
|
|
raise "Invalid user" unless user
|
|
|
|
options.reverse_merge!(content_method: :login, title_method: :login, class: :nickname)
|
|
content_text = options.delete(:content_text)
|
|
content_text ||= user.send(options.delete(:content_method))
|
|
options[:title] ||= user.send(options.delete(:title_method))
|
|
link_to(h(content_text), user_path(user), options)
|
|
end
|
|
|
|
#
|
|
# Link to login page using remote ip address as link content
|
|
#
|
|
# The :title (and thus, tooltip) is set to the IP address
|
|
#
|
|
# Examples:
|
|
# link_to_login_with_IP
|
|
# # => <a href="/login" title="169.69.69.69">169.69.69.69</a>
|
|
#
|
|
# link_to_login_with_IP :content_text => 'not signed in'
|
|
# # => <a href="/login" title="169.69.69.69">not signed in</a>
|
|
#
|
|
def link_to_login_with_IP(content_text = nil, options = {}) # rubocop:disable Naming/MethodName
|
|
ip_addr = request.remote_ip
|
|
content_text ||= ip_addr
|
|
options.reverse_merge!(title: ip_addr)
|
|
if tag = options.delete(:tag)
|
|
content_tag(tag, h(content_text), options)
|
|
else
|
|
link_to(h(content_text), login_path, options)
|
|
end
|
|
end
|
|
|
|
#
|
|
# Link to the current user's page (using link_to_user) or to the login page
|
|
# (using link_to_login_with_IP).
|
|
#
|
|
def link_to_current_user(options = {})
|
|
if current_user
|
|
link_to_user(current_user, options)
|
|
else
|
|
content_text = options.delete(:content_text) || 'not signed in'
|
|
# kill ignored options from link_to_user
|
|
%i(content_method title_method).each { |opt| options.delete(opt) }
|
|
link_to_login_with_IP(content_text, options)
|
|
end
|
|
end
|
|
end
|