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>
59 lines
1.5 KiB
Ruby
59 lines
1.5 KiB
Ruby
require 'digest/sha1'
|
|
|
|
class User < ApplicationRecord
|
|
has_many :maps
|
|
has_many :tags
|
|
has_many :comments
|
|
has_many :exports
|
|
has_many :warpables, through: :maps
|
|
|
|
validates_presence_of :login
|
|
validates_length_of :login, within: 3..40
|
|
validates_uniqueness_of :login
|
|
validates_length_of :name, maximum: 100
|
|
|
|
validates_presence_of :email
|
|
validates_length_of :email, within: 6..100 # r@a.wk
|
|
validates_uniqueness_of :email
|
|
|
|
# Prevents a user from submitting a crafted form that bypasses activation
|
|
# anything else you want your user to change should be added here.
|
|
|
|
# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
|
|
#
|
|
# uff. this is really an authorization, not authentication routine.
|
|
# We really need a Dispatch Chain here or something.
|
|
# This will also let us return a human error message.
|
|
#
|
|
|
|
def login=(value)
|
|
write_attribute(:login, (value ? value.downcase : nil))
|
|
end
|
|
|
|
def email=(value)
|
|
write_attribute(:email, (value ? value.downcase : nil))
|
|
end
|
|
|
|
def last_action
|
|
maps.order('updated_at DESC').limit(1).first.updated_at
|
|
end
|
|
|
|
# Permissions for editing and deleting resources
|
|
|
|
def owns?(resource)
|
|
resource.user_id.to_i == id
|
|
end
|
|
|
|
def owns_map?(resource)
|
|
resource.respond_to?(:map) && resource.map.user_id.to_i == id
|
|
end
|
|
|
|
def can_delete?(resource)
|
|
owns?(resource) || owns_map?(resource) || role == "admin"
|
|
end
|
|
|
|
def can_edit?(resource)
|
|
owns?(resource)
|
|
end
|
|
end
|