Metrics/PerceivedComplexity:
Max: 24
-# Offense count: 164
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SupportedStyles, Include.
-Rails/ActionFilter:
- Enabled: false
-
# Offense count: 2
# Configuration parameters: Include.
Rails/HasAndBelongsToMany:
Enabled: false
-# Offense count: 17
-# Cop supports --auto-correct.
-# Configuration parameters: Include.
-Rails/ReadWriteAttribute:
- Enabled: false
-
-# Offense count: 123
-# Configuration parameters: Include.
-Rails/Validation:
- Enabled: false
-
# Offense count: 5
Style/AccessorMethodName:
Enabled: false
class AmfController < ApplicationController
include Potlatch
- skip_before_filter :verify_authenticity_token
- before_filter :check_api_writable
+ skip_before_action :verify_authenticity_token
+ before_action :check_api_writable
# Main AMF handlers: process the raw AMF string (using AMF library) and
# calls each action (private method) accordingly.
class ApiController < ApplicationController
- skip_before_filter :verify_authenticity_token
- before_filter :check_api_readable, :except => [:capabilities]
- before_filter :setup_user_auth, :only => [:permissions]
- after_filter :compress_output
- around_filter :api_call_handle_error, :api_call_timeout
+ skip_before_action :verify_authenticity_token
+ before_action :check_api_readable, :except => [:capabilities]
+ before_action :setup_user_auth, :only => [:permissions]
+ after_action :compress_output
+ around_action :api_call_handle_error, :api_call_timeout
# Get an XML response containing a list of tracepoints that have been uploaded
# within the specified bounding box, and in the specified page.
protect_from_forgery
- before_filter :fetch_body
+ before_action :fetch_body
def authorize_web
if session[:user]
class BrowseController < ApplicationController
layout :map_layout
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :except => [:query] { |c| c.check_database_readable(true) }
- before_filter :require_oauth
- around_filter :web_timeout
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :except => [:query] { |c| c.check_database_readable(true) }
+ before_action :require_oauth
+ around_action :web_timeout
def relation
@type = "relation"
layout "site"
require "xml/libxml"
- skip_before_filter :verify_authenticity_token, :except => [:list]
- before_filter :authorize_web, :only => [:list, :feed, :comments_feed]
- before_filter :set_locale, :only => [:list, :feed, :comments_feed]
- before_filter :authorize, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
- before_filter :require_moderator, :only => [:hide_comment, :unhide_comment]
- before_filter :require_allow_write_api, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
- before_filter :require_public_data, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe]
- before_filter :check_api_writable, :only => [:create, :update, :delete, :upload, :include, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
- before_filter :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query, :list, :feed, :comment, :subscribe, :unsubscribe, :comments_feed]
- before_filter(:only => [:list, :feed, :comments_feed]) { |c| c.check_database_readable(true) }
- after_filter :compress_output
- around_filter :api_call_handle_error, :except => [:list, :feed, :comments_feed]
- around_filter :web_timeout, :only => [:list, :feed, :comments_feed]
+ skip_before_action :verify_authenticity_token, :except => [:list]
+ before_action :authorize_web, :only => [:list, :feed, :comments_feed]
+ before_action :set_locale, :only => [:list, :feed, :comments_feed]
+ before_action :authorize, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
+ before_action :require_moderator, :only => [:hide_comment, :unhide_comment]
+ before_action :require_allow_write_api, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
+ before_action :require_public_data, :only => [:create, :update, :delete, :upload, :include, :close, :comment, :subscribe, :unsubscribe]
+ before_action :check_api_writable, :only => [:create, :update, :delete, :upload, :include, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
+ before_action :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query, :list, :feed, :comment, :subscribe, :unsubscribe, :comments_feed]
+ before_action(:only => [:list, :feed, :comments_feed]) { |c| c.check_database_readable(true) }
+ after_action :compress_output
+ around_action :api_call_handle_error, :except => [:list, :feed, :comments_feed]
+ around_action :web_timeout, :only => [:list, :feed, :comments_feed]
# Helper methods for checking consistency
include ConsistencyValidations
class DiaryEntryController < ApplicationController
layout "site", :except => :rss
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_user, :only => [:new, :edit, :comment, :hide, :hidecomment]
- before_filter :lookup_this_user, :only => [:view, :comments]
- before_filter :check_database_readable
- before_filter :check_database_writable, :only => [:new, :edit]
- before_filter :require_administrator, :only => [:hide, :hidecomment]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_user, :only => [:new, :edit, :comment, :hide, :hidecomment]
+ before_action :lookup_this_user, :only => [:view, :comments]
+ before_action :check_database_readable
+ before_action :check_database_writable, :only => [:new, :edit]
+ before_action :require_administrator, :only => [:hide, :hidecomment]
def new
@title = t "diary_entry.new.title"
class DirectionsController < ApplicationController
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_oauth, :only => [:search]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_oauth, :only => [:search]
def search
render :layout => map_layout
class ExportController < ApplicationController
- before_filter :authorize_web
- before_filter :set_locale
+ before_action :authorize_web
+ before_action :set_locale
caches_page :embed
require "net/http"
require "rexml/document"
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_oauth, :only => [:search]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_oauth, :only => [:search]
def search
normalize_params
class MessageController < ApplicationController
layout "site"
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_user
- before_filter :lookup_this_user, :only => [:new]
- before_filter :check_database_readable
- before_filter :check_database_writable, :only => [:new, :reply, :mark]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_user
+ before_action :lookup_this_user, :only => [:new]
+ before_action :check_database_readable
+ before_action :check_database_writable, :only => [:new, :reply, :mark]
# Allow the user to write a new message to another user. This action also
# deals with the sending of that message to the other user when the user
class NodeController < ApplicationController
require "xml/libxml"
- skip_before_filter :verify_authenticity_token
- before_filter :authorize, :only => [:create, :update, :delete]
- before_filter :require_allow_write_api, :only => [:create, :update, :delete]
- before_filter :require_public_data, :only => [:create, :update, :delete]
- before_filter :check_api_writable, :only => [:create, :update, :delete]
- before_filter :check_api_readable, :except => [:create, :update, :delete]
- after_filter :compress_output
- around_filter :api_call_handle_error, :api_call_timeout
+ skip_before_action :verify_authenticity_token
+ before_action :authorize, :only => [:create, :update, :delete]
+ before_action :require_allow_write_api, :only => [:create, :update, :delete]
+ before_action :require_public_data, :only => [:create, :update, :delete]
+ before_action :check_api_writable, :only => [:create, :update, :delete]
+ before_action :check_api_readable, :except => [:create, :update, :delete]
+ after_action :compress_output
+ around_action :api_call_handle_error, :api_call_timeout
# Create a node from XML.
def create
class NotesController < ApplicationController
layout "site", :only => [:mine]
- before_filter :check_api_readable
- before_filter :authorize_web, :only => [:mine]
- before_filter :setup_user_auth, :only => [:create, :comment]
- before_filter :authorize, :only => [:close, :reopen, :destroy]
- before_filter :require_moderator, :only => [:destroy]
- before_filter :check_api_writable, :only => [:create, :comment, :close, :reopen, :destroy]
- before_filter :require_allow_write_notes, :only => [:create, :comment, :close, :reopen, :destroy]
- before_filter :set_locale
- after_filter :compress_output
- around_filter :api_call_handle_error, :api_call_timeout
+ before_action :check_api_readable
+ before_action :authorize_web, :only => [:mine]
+ before_action :setup_user_auth, :only => [:create, :comment]
+ before_action :authorize, :only => [:close, :reopen, :destroy]
+ before_action :require_moderator, :only => [:destroy]
+ before_action :check_api_writable, :only => [:create, :comment, :close, :reopen, :destroy]
+ before_action :require_allow_write_notes, :only => [:create, :comment, :close, :reopen, :destroy]
+ before_action :set_locale
+ after_action :compress_output
+ around_action :api_call_handle_error, :api_call_timeout
##
# Return a list of notes in a given area
class OauthClientsController < ApplicationController
layout "site"
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_user
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_user
def index
@client_applications = @user.client_applications
class OldController < ApplicationController
require "xml/libxml"
- skip_before_filter :verify_authenticity_token
- before_filter :setup_user_auth, :only => [:history, :version]
- before_filter :authorize, :only => [:redact]
- before_filter :authorize_moderator, :only => [:redact]
- before_filter :require_allow_write_api, :only => [:redact]
- before_filter :check_api_readable
- before_filter :check_api_writable, :only => [:redact]
- after_filter :compress_output
- around_filter :api_call_handle_error, :api_call_timeout
- before_filter :lookup_old_element, :except => [:history]
- before_filter :lookup_old_element_versions, :only => [:history]
+ skip_before_action :verify_authenticity_token
+ before_action :setup_user_auth, :only => [:history, :version]
+ before_action :authorize, :only => [:redact]
+ before_action :authorize_moderator, :only => [:redact]
+ before_action :require_allow_write_api, :only => [:redact]
+ before_action :check_api_readable
+ before_action :check_api_writable, :only => [:redact]
+ after_action :compress_output
+ around_action :api_call_handle_error, :api_call_timeout
+ before_action :lookup_old_element, :except => [:history]
+ before_action :lookup_old_element_versions, :only => [:history]
def history
# the .where() method used in the lookup_old_element_versions
class RedactionsController < ApplicationController
layout "site"
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_user, :only => [:new, :create, :edit, :update, :destroy]
- before_filter :require_moderator, :only => [:new, :create, :edit, :update, :destroy]
- before_filter :lookup_redaction, :only => [:show, :edit, :update, :destroy]
- before_filter :check_database_readable
- before_filter :check_database_writable, :only => [:create, :update, :destroy]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_user, :only => [:new, :create, :edit, :update, :destroy]
+ before_action :require_moderator, :only => [:new, :create, :edit, :update, :destroy]
+ before_action :lookup_redaction, :only => [:show, :edit, :update, :destroy]
+ before_action :check_database_readable
+ before_action :check_database_writable, :only => [:create, :update, :destroy]
def index
@redactions = Redaction.order(:id)
class RelationController < ApplicationController
require "xml/libxml"
- skip_before_filter :verify_authenticity_token
- before_filter :authorize, :only => [:create, :update, :delete]
- before_filter :require_allow_write_api, :only => [:create, :update, :delete]
- before_filter :require_public_data, :only => [:create, :update, :delete]
- before_filter :check_api_writable, :only => [:create, :update, :delete]
- before_filter :check_api_readable, :except => [:create, :update, :delete]
- after_filter :compress_output
- around_filter :api_call_handle_error, :api_call_timeout
+ skip_before_action :verify_authenticity_token
+ before_action :authorize, :only => [:create, :update, :delete]
+ before_action :require_allow_write_api, :only => [:create, :update, :delete]
+ before_action :require_public_data, :only => [:create, :update, :delete]
+ before_action :check_api_writable, :only => [:create, :update, :delete]
+ before_action :check_api_readable, :except => [:create, :update, :delete]
+ after_action :compress_output
+ around_action :api_call_handle_error, :api_call_timeout
def create
assert_method :put
# Support searching for nodes, ways, or all
# Can search by tag k, v, or both (type->k,value->v)
# Can search by name (k=name,v=....)
- skip_before_filter :verify_authenticity_token
- after_filter :compress_output
+ skip_before_action :verify_authenticity_token
+ after_action :compress_output
def search_all
do_search(true, true, true)
layout "site"
layout :map_layout, :only => [:index, :export]
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :redirect_browse_params, :only => :index
- before_filter :redirect_map_params, :only => [:index, :edit, :export]
- before_filter :require_user, :only => [:welcome]
- before_filter :require_oauth, :only => [:index]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :redirect_browse_params, :only => :index
+ before_action :redirect_map_params, :only => [:index, :edit, :export]
+ before_action :require_user, :only => [:welcome]
+ before_action :require_oauth, :only => [:index]
def index
unless STATUS == :database_readonly || STATUS == :database_offline
class SwfController < ApplicationController
- skip_before_filter :verify_authenticity_token
- before_filter :check_api_readable
+ skip_before_action :verify_authenticity_token
+ before_action :check_api_readable
# to log:
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")
class TraceController < ApplicationController
layout "site"
- skip_before_filter :verify_authenticity_token, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_user, :only => [:mine, :create, :edit, :delete]
- before_filter :authorize, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
- before_filter :check_database_readable, :except => [:api_read, :api_data]
- before_filter :check_database_writable, :only => [:create, :edit, :delete, :api_create, :api_update, :api_delete]
- before_filter :check_api_readable, :only => [:api_read, :api_data]
- before_filter :check_api_writable, :only => [:api_create, :api_update, :api_delete]
- before_filter :require_allow_read_gpx, :only => [:api_read, :api_data]
- before_filter :require_allow_write_gpx, :only => [:api_create, :api_update, :api_delete]
- before_filter :offline_warning, :only => [:mine, :view]
- before_filter :offline_redirect, :only => [:create, :edit, :delete, :data, :api_create, :api_delete, :api_data]
- around_filter :api_call_handle_error, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
+ skip_before_action :verify_authenticity_token, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_user, :only => [:mine, :create, :edit, :delete]
+ before_action :authorize, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
+ before_action :check_database_readable, :except => [:api_read, :api_data]
+ before_action :check_database_writable, :only => [:create, :edit, :delete, :api_create, :api_update, :api_delete]
+ before_action :check_api_readable, :only => [:api_read, :api_data]
+ before_action :check_api_writable, :only => [:api_create, :api_update, :api_delete]
+ before_action :require_allow_read_gpx, :only => [:api_read, :api_data]
+ before_action :require_allow_write_gpx, :only => [:api_create, :api_update, :api_delete]
+ before_action :offline_warning, :only => [:mine, :view]
+ before_action :offline_redirect, :only => [:create, :edit, :delete, :data, :api_create, :api_delete, :api_data]
+ around_action :api_call_handle_error, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
class UserBlocksController < ApplicationController
layout "site"
- before_filter :authorize_web
- before_filter :set_locale
- before_filter :require_user, :only => [:new, :create, :edit, :update, :revoke]
- before_filter :require_moderator, :only => [:new, :create, :edit, :update, :revoke]
- before_filter :lookup_this_user, :only => [:new, :create, :blocks_on, :blocks_by]
- before_filter :lookup_user_block, :only => [:show, :edit, :update, :revoke]
- before_filter :require_valid_params, :only => [:create, :update]
- before_filter :check_database_readable
- before_filter :check_database_writable, :only => [:create, :update, :revoke]
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_user, :only => [:new, :create, :edit, :update, :revoke]
+ before_action :require_moderator, :only => [:new, :create, :edit, :update, :revoke]
+ before_action :lookup_this_user, :only => [:new, :create, :blocks_on, :blocks_by]
+ before_action :lookup_user_block, :only => [:show, :edit, :update, :revoke]
+ before_action :require_valid_params, :only => [:create, :update]
+ before_action :check_database_readable
+ before_action :check_database_writable, :only => [:create, :update, :revoke]
def index
@user_blocks_pages, @user_blocks = paginate(:user_blocks,
class UserController < ApplicationController
layout "site", :except => [:api_details]
- skip_before_filter :verify_authenticity_token, :only => [:api_read, :api_details, :api_gpx_files, :auth_success]
- before_filter :disable_terms_redirect, :only => [:terms, :save, :logout, :api_details]
- before_filter :authorize, :only => [:api_details, :api_gpx_files]
- before_filter :authorize_web, :except => [:api_read, :api_details, :api_gpx_files]
- before_filter :set_locale, :except => [:api_read, :api_details, :api_gpx_files]
- before_filter :require_user, :only => [:account, :go_public, :make_friend, :remove_friend]
- before_filter :require_self, :only => [:account]
- before_filter :check_database_readable, :except => [:login, :api_read, :api_details, :api_gpx_files]
- before_filter :check_database_writable, :only => [:new, :account, :confirm, :confirm_email, :lost_password, :reset_password, :go_public, :make_friend, :remove_friend]
- before_filter :check_api_readable, :only => [:api_read, :api_details, :api_gpx_files]
- before_filter :require_allow_read_prefs, :only => [:api_details]
- before_filter :require_allow_read_gpx, :only => [:api_gpx_files]
- before_filter :require_cookies, :only => [:new, :login, :confirm]
- before_filter :require_administrator, :only => [:set_status, :delete, :list]
- around_filter :api_call_handle_error, :only => [:api_read, :api_details, :api_gpx_files]
- before_filter :lookup_user_by_id, :only => [:api_read]
- before_filter :lookup_user_by_name, :only => [:set_status, :delete]
+ skip_before_action :verify_authenticity_token, :only => [:api_read, :api_details, :api_gpx_files, :auth_success]
+ before_action :disable_terms_redirect, :only => [:terms, :save, :logout, :api_details]
+ before_action :authorize, :only => [:api_details, :api_gpx_files]
+ before_action :authorize_web, :except => [:api_read, :api_details, :api_gpx_files]
+ before_action :set_locale, :except => [:api_read, :api_details, :api_gpx_files]
+ before_action :require_user, :only => [:account, :go_public, :make_friend, :remove_friend]
+ before_action :require_self, :only => [:account]
+ before_action :check_database_readable, :except => [:login, :api_read, :api_details, :api_gpx_files]
+ before_action :check_database_writable, :only => [:new, :account, :confirm, :confirm_email, :lost_password, :reset_password, :go_public, :make_friend, :remove_friend]
+ before_action :check_api_readable, :only => [:api_read, :api_details, :api_gpx_files]
+ before_action :require_allow_read_prefs, :only => [:api_details]
+ before_action :require_allow_read_gpx, :only => [:api_gpx_files]
+ before_action :require_cookies, :only => [:new, :login, :confirm]
+ before_action :require_administrator, :only => [:set_status, :delete, :list]
+ around_action :api_call_handle_error, :only => [:api_read, :api_details, :api_gpx_files]
+ before_action :lookup_user_by_id, :only => [:api_read]
+ before_action :lookup_user_by_name, :only => [:set_status, :delete]
def terms
@legale = params[:legale] || OSM.ip_to_country(request.remote_ip) || DEFAULT_LEGALE
# Update and read user preferences, which are arbitrayr key/val pairs
class UserPreferenceController < ApplicationController
- skip_before_filter :verify_authenticity_token
- before_filter :authorize
- before_filter :require_allow_read_prefs, :only => [:read_one, :read]
- before_filter :require_allow_write_prefs, :except => [:read_one, :read]
- around_filter :api_call_handle_error
+ skip_before_action :verify_authenticity_token
+ before_action :authorize
+ before_action :require_allow_read_prefs, :only => [:read_one, :read]
+ before_action :require_allow_write_prefs, :except => [:read_one, :read]
+ around_action :api_call_handle_error
##
# return all the preferences as an XML document
class UserRolesController < ApplicationController
layout "site"
- before_filter :authorize_web
- before_filter :require_user
- before_filter :lookup_this_user
- before_filter :require_administrator
- before_filter :require_valid_role
- before_filter :not_in_role, :only => [:grant]
- before_filter :in_role, :only => [:revoke]
+ before_action :authorize_web
+ before_action :require_user
+ before_action :lookup_this_user
+ before_action :require_administrator
+ before_action :require_valid_role
+ before_action :not_in_role, :only => [:grant]
+ before_action :in_role, :only => [:revoke]
def grant
@this_user.roles.create(:role => @role, :granter_id => @user.id)
class WayController < ApplicationController
require "xml/libxml"
- skip_before_filter :verify_authenticity_token
- before_filter :authorize, :only => [:create, :update, :delete]
- before_filter :require_allow_write_api, :only => [:create, :update, :delete]
- before_filter :require_public_data, :only => [:create, :update, :delete]
- before_filter :check_api_writable, :only => [:create, :update, :delete]
- before_filter :check_api_readable, :except => [:create, :update, :delete]
- after_filter :compress_output
- around_filter :api_call_handle_error, :api_call_timeout
+ skip_before_action :verify_authenticity_token
+ before_action :authorize, :only => [:create, :update, :delete]
+ before_action :require_allow_write_api, :only => [:create, :update, :delete]
+ before_action :require_public_data, :only => [:create, :update, :delete]
+ before_action :check_api_writable, :only => [:create, :update, :delete]
+ before_action :check_api_readable, :except => [:create, :update, :delete]
+ after_action :compress_output
+ around_action :api_call_handle_error, :api_call_timeout
def create
assert_method :put
scope :valid, -> { where(:invalidated_at => nil) }
- validates_presence_of :user, :secret
+ validates :user, :secret, :presence => true
before_create :set_authorized_at
has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "ChangesetComment"
has_and_belongs_to_many :subscribers, :class_name => "User", :join_table => "changesets_subscribers", :association_foreign_key => "subscriber_id"
- validates_presence_of :id, :on => :update
- validates_presence_of :user_id, :created_at, :closed_at, :num_changes
- validates_uniqueness_of :id
- validates_numericality_of :id, :on => :update, :integer_only => true
- validates_numericality_of :min_lat, :max_lat, :min_lon, :max_lat, :allow_nil => true, :integer_only => true
- validates_numericality_of :user_id, :integer_only => true
- validates_numericality_of :num_changes, :integer_only => true, :greater_than_or_equal_to => 0
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :user_id, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :num_changes, :presence => true,
+ :numericality => { :integer_only => true,
+ :greater_than_or_equal_to => 0 }
+ validates :created_at, :closed_at, :presence => true
+ validates :min_lat, :max_lat, :min_lon, :max_lat, :allow_nil => true,
+ :numericality => { :integer_only => true }
before_save :update_closed_at
belongs_to :changeset
belongs_to :author, :class_name => "User"
- validates_presence_of :id, :on => :update # is it necessary?
- validates_uniqueness_of :id
- validates_presence_of :changeset
- validates_associated :changeset
- validates_presence_of :author
- validates_associated :author
- validates :visible, :inclusion => { :in => [true, false] }
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :changeset, :presence => true, :associated => true
+ validates :author, :presence => true, :associated => true
+ validates :visible, :inclusion => [true, false]
# Return the comment text
def body
- RichText.new("text", read_attribute(:body))
+ RichText.new("text", self[:body])
end
end
belongs_to :changeset
- validates_presence_of :changeset
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => :changeset_id
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :changeset, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => :changeset_id }
end
has_many :oauth2_verifiers
has_many :oauth_tokens
- validates_presence_of :name, :url, :key, :secret
- validates_uniqueness_of :key
- validates_format_of :url, :with => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i
- validates_format_of :support_url, :with => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i, :allow_blank => true
- validates_format_of :callback_url, :with => %r{\A[a-z][a-z0-9.+-]*://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i, :allow_blank => true
+ validates :key, :presence => true, :uniqueness => true
+ validates :name, :url, :secret, :presence => true
+ validates :url, :format => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i
+ validates :support_url, :callback_url, :allow_blank => true, :format => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i
before_validation :generate_keys, :on => :create
belongs_to :user
belongs_to :diary_entry
- validates_presence_of :body
- validates_associated :diary_entry
+ validates :body, :presence => true
+ validates :diary_entry, :user, :associated => true
after_save :spam_check
def body
- RichText.new(read_attribute(:body_format), read_attribute(:body))
+ RichText.new(self[:body_format], self[:body])
end
def digest
scope :visible, -> { where(:visible => true) }
- validates_presence_of :title, :body
- validates_length_of :title, :within => 1..255
- # validates_length_of :language, :within => 2..5, :allow_nil => false
- validates_numericality_of :latitude, :allow_nil => true,
- :greater_than_or_equal_to => -90, :less_than_or_equal_to => 90
- validates_numericality_of :longitude, :allow_nil => true,
- :greater_than_or_equal_to => -180, :less_than_or_equal_to => 180
- validates_associated :language
+ validates :title, :body, :presence => true
+ validates :title, :length => 1..255
+ validates :latitude, :allow_nil => true,
+ :numericality => { :greater_than_or_equal_to => -90,
+ :less_than_or_equal_to => 90 }
+ validates :longitude, :allow_nil => true,
+ :numericality => { :greater_than_or_equal_to => -180,
+ :less_than_or_equal_to => 180 }
+ validates :language, :user, :associated => true
after_save :spam_check
def body
- RichText.new(read_attribute(:body_format), read_attribute(:body))
+ RichText.new(self[:body_format], self[:body])
end
private
belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id
- validates_presence_of :title, :body, :sent_on, :sender, :recipient
- validates_length_of :title, :within => 1..255
- validates_inclusion_of :message_read, :in => [true, false]
- validates_as_utf8 :title
+ validates :title, :presence => true, :utf8 => true, :length => 1..255
+ validates :body, :sent_on, :sender, :recipient, :presence => true
def self.from_mail(mail, from, to)
if mail.multipart?
end
def body
- RichText.new(read_attribute(:body_format), read_attribute(:body))
+ RichText.new(self[:body_format], self[:body])
end
def digest
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
- validates_presence_of :id, :on => :update
- validates_presence_of :timestamp, :version, :changeset_id
- validates_uniqueness_of :id
- validates_inclusion_of :visible, :in => [true, false]
- validates_numericality_of :latitude, :longitude, :changeset_id, :version, :integer_only => true
- validates_numericality_of :id, :on => :update, :integer_only => true
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :version, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :changeset_id, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :latitude, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :longitude, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :timestamp, :presence => true
+ validates :changeset, :associated => true
+ validates :visible, :inclusion => [true, false]
+
validate :validate_position
- validates_associated :changeset
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }
belongs_to :node
- validates_presence_of :node
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => :node_id
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :node, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => :node_id }
end
has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
- validates_presence_of :id, :on => :update
- validates_uniqueness_of :id
- validates_numericality_of :latitude, :only_integer => true
- validates_numericality_of :longitude, :only_integer => true
- validates_presence_of :closed_at if :status == "closed"
- validates_inclusion_of :status, :in => %w(open closed hidden)
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :latitude, :longitude, :numericality => { :only_integer => true }
+ validates :closed_at, :presence => true, :if => proc { :status == "closed" }
+ validates :status, :inclusion => %w(open closed hidden)
+
validate :validate_position
scope :visible, -> { where("status != 'hidden'") }
belongs_to :note, :foreign_key => :note_id, :touch => true
belongs_to :author, :class_name => "User", :foreign_key => :author_id
- validates_presence_of :id, :on => :update
- validates_uniqueness_of :id
- validates_presence_of :note_id
- validates_associated :note
- validates_presence_of :visible
- validates_associated :author
- validates_inclusion_of :event, :in => %w(opened closed reopened commented hidden)
- validates_format_of :body, :with => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :note, :presence => true, :associated => true
+ validates :visible, :inclusion => [true, false]
+ validates :author, :associated => true
+ validates :event, :inclusion => %w(opened closed reopened commented hidden)
+ validates :body, :format => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
# Return the comment text
def body
- RichText.new("text", read_attribute(:body))
+ RichText.new("text", self[:body])
end
end
class Oauth2Verifier < OauthToken
- validates_presence_of :user
+ validates :user, :presence => true, :associated => true
+
attr_accessor :state
def exchange!(_params = {})
# Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
# Thus you can use the same nonce with a different timestamp and viceversa.
class OauthNonce < ActiveRecord::Base
- validates_presence_of :nonce, :timestamp
- validates_uniqueness_of :nonce, :scope => :timestamp
+ validates :timestamp, :presence => true
+ validates :nonce, :presence => true, :uniqueness => { :scope => :timestamp }
# Remembers a nonce and it's associated timestamp. It returns false if it has already been used
def self.remember(nonce, timestamp)
scope :authorized, -> { where("authorized_at IS NOT NULL and invalidated_at IS NULL") }
- validates_uniqueness_of :token
- validates_presence_of :client_application, :token
+ validates :token, :presence => true, :uniqueness => true
+ validates :user, :associated => true
+ validates :client_application, :presence => true
before_validation :generate_keys, :on => :create
# the queries generated by Redactable will use the wrong table name.
include Redactable
- validates_presence_of :changeset_id, :timestamp
- validates_inclusion_of :visible, :in => [true, false]
- validates_numericality_of :latitude, :longitude
+ validates :changeset, :presence => true, :associated => true
+ validates :latitude, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :longitude, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :timestamp, :presence => true
+ validates :visible, :inclusion => [true, false]
+
validate :validate_position
- validates_associated :changeset
belongs_to :changeset
belongs_to :redaction
belongs_to :old_node, :foreign_key => [:node_id, :version]
- validates_presence_of :old_node
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => [:node_id, :version]
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :old_node, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => [:node_id, :version] }
end
has_many :old_members, -> { order(:sequence_id) }, :class_name => "OldRelationMember", :foreign_key => [:relation_id, :version]
has_many :old_tags, :class_name => "OldRelationTag", :foreign_key => [:relation_id, :version]
- validates_associated :changeset
+ validates :changeset, :presence => true, :associated => true
+ validates :timestamp, :presence => true
+ validates :visible, :inclusion => [true, false]
def self.from_relation(relation)
old_relation = OldRelation.new
belongs_to :old_relation, :foreign_key => [:relation_id, :version]
- validates_presence_of :old_relation
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => [:relation_id, :version]
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :old_relation, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => [:relation_id, :version] }
end
has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version]
has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version]
- validates_associated :changeset
+ validates :changeset, :presence => true, :associated => true
+ validates :timestamp, :presence => true
+ validates :visible, :inclusion => [true, false]
def self.from_way(way)
old_way = OldWay.new
belongs_to :old_way, :foreign_key => [:way_id, :version]
- validates_presence_of :old_way
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => [:way_id, :version]
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :old_way, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => [:way_id, :version] }
end
# this method overrides the AR default to provide the rich
# text object for the description field.
def description
- RichText.new(read_attribute(:description_format), read_attribute(:description))
+ RichText.new(self[:description_format], self[:description])
end
end
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
- validates_presence_of :id, :on => :update
- validates_presence_of :timestamp, :version, :changeset_id
- validates_uniqueness_of :id
- validates_inclusion_of :visible, :in => [true, false]
- validates_numericality_of :id, :on => :update, :integer_only => true
- validates_numericality_of :changeset_id, :version, :integer_only => true
- validates_associated :changeset
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :version, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :changeset_id, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :timestamp, :presence => true
+ validates :changeset, :associated => true
+ validates :visible, :inclusion => [true, false]
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }
belongs_to :relation
- validates_presence_of :relation
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => :relation_id
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :relation, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => :relation_id }
end
params = { :user => user, :client_application => client_application }
# copy the permissions from the authorised request token to the access token
client_application.permissions.each do |p|
- params[p] = read_attribute(p)
+ params[p] = self[p]
end
access_token = AccessToken.create(params)
scope :visible_to_all, -> { where(:visibility => %w(public identifiable)) }
scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
- validates_presence_of :user_id, :name, :timestamp
- validates_presence_of :description, :on => :create
- validates_length_of :name, :maximum => 255
- validates_length_of :description, :maximum => 255
- # validates_numericality_of :latitude, :longitude
- validates_inclusion_of :inserted, :in => [true, false]
- validates_inclusion_of :visibility, :in => %w(private public trackable identifiable)
+ validates :user, :presence => true, :associated => true
+ validates :name, :presence => true, :length => 1..255
+ validates :description, :presence => { :on => :create }, :length => 1..255
+ validates :timestamp, :presence => true
+ validates :visibility, :inclusion => %w(private public trackable identifiable)
def destroy
super
self.table_name = "gps_points"
- validates_numericality_of :trackid, :only_integer => true
- validates_numericality_of :latitude, :only_integer => true
- validates_numericality_of :longitude, :only_integer => true
- validates_associated :trace
- validates_presence_of :timestamp
+ validates :trackid, :numericality => { :only_integer => true }
+ validates :latitude, :longitude, :numericality => { :only_integer => true }
+ validates :trace, :associated => true
+ validates :timestamp, :presence => true
belongs_to :trace, :foreign_key => "gpx_id"
class Tracetag < ActiveRecord::Base
self.table_name = "gpx_file_tags"
- validates_format_of :tag, :with => /\A[^\/;.,?]*\z/
- validates_length_of :tag, :within => 1..255
-
belongs_to :trace, :foreign_key => "gpx_id"
+
+ validates :trace, :presence => true, :associated => true
+ validates :tag, :length => 1..255, :format => /\A[^\/;.,?]*\z/
end
:default_url => "/assets/:class/:attachment/:style.png",
:styles => { :large => "100x100>", :small => "50x50>" }
- validates_presence_of :email, :display_name
- validates_confirmation_of :email # , :message => ' addresses must match'
- validates_confirmation_of :pass_crypt # , :message => ' must match the confirmation password'
- validates_uniqueness_of :display_name, :allow_nil => true, :case_sensitive => false, :if => proc { |u| u.display_name_changed? }
- validates_uniqueness_of :email, :case_sensitive => false, :if => proc { |u| u.email_changed? }
- validates_length_of :pass_crypt, :within => 8..255
- validates_length_of :display_name, :within => 3..255, :allow_nil => true
+ validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
+ :exclusion => %w(new terms save confirm confirm-email go_public reset-password forgot-password suspended)
+ validates :display_name, :if => proc { |u| u.display_name_changed? },
+ :uniqueness => { :case_sensitive => false }
+ validates :display_name, :if => proc { |u| u.display_name_changed? },
+ :format => { :with => /\A[^\x00-\x1f\x7f\ufffe\uffff\/;.,?%#]*\z/ }
+ validates :display_name, :if => proc { |u| u.display_name_changed? },
+ :format => { :with => /\A\S/, :message => "has leading whitespace" }
+ validates :display_name, :if => proc { |u| u.display_name_changed? },
+ :format => { :with => /\S\z/, :message => "has trailing whitespace" }
+ validates :email, :presence => true, :confirmation => true
+ validates :email, :if => proc { |u| u.email_changed? },
+ :uniqueness => { :case_sensitive => false }
+ validates :pass_crypt, :confirmation => true, :length => 8..255
+ validates :home_lat, :home_lon, :allow_nil => true, :numericality => true
+ validates :home_zoom, :allow_nil => true, :numericality => { :only_integer => true }
+ validates :preferred_editor, :inclusion => Editors::ALL_EDITORS, :allow_nil => true
+ validates :image, :attachment_content_type => { :content_type => /\Aimage\/.*\Z/ }
+
validates_email_format_of :email, :if => proc { |u| u.email_changed? }
validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_email_changed? }
- validates_format_of :display_name, :with => /\A[^\x00-\x1f\x7f\ufffe\uffff\/;.,?%#]*\z/, :if => proc { |u| u.display_name_changed? }
- validates_format_of :display_name, :with => /\A\S/, :message => "has leading whitespace", :if => proc { |u| u.display_name_changed? }
- validates_format_of :display_name, :with => /\S\z/, :message => "has trailing whitespace", :if => proc { |u| u.display_name_changed? }
- validates_exclusion_of :display_name, :in => %w(new terms save confirm confirm-email go_public reset-password forgot-password suspended)
- validates_numericality_of :home_lat, :allow_nil => true
- validates_numericality_of :home_lon, :allow_nil => true
- validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
- validates_inclusion_of :preferred_editor, :in => Editors::ALL_EDITORS, :allow_nil => true
- validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
after_initialize :set_defaults
before_save :encrypt_password
end
def description
- RichText.new(read_attribute(:description_format), read_attribute(:description))
+ RichText.new(self[:description_format], self[:description])
end
def languages
- attribute_present?(:languages) ? read_attribute(:languages).split(/ *, */) : []
+ attribute_present?(:languages) ? self[:languages].split(/ *, */) : []
end
def languages=(languages)
- write_attribute(:languages, languages.join(","))
+ self[:languages] = languages.join(",")
end
def preferred_language
##
# return a renderable version of the reason text.
def reason
- RichText.new(read_attribute(:reason_format), read_attribute(:reason))
+ RichText.new(self[:reason_format], self[:reason])
end
##
belongs_to :user
- validates_length_of :k, :within => 1..255
- validates_length_of :v, :within => 1..255
+ validates :user, :presence => true, :associated => true
+ validates :k, :v, :length => 1..255
# Turn this Node in to an XML Node without the <osm> wrapper.
def to_xml_node
ALL_ROLES = %w(administrator moderator)
- validates_inclusion_of :role, :in => ALL_ROLES
- validates_uniqueness_of :role, :scope => :user_id
+ validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id }
end
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
- validates_presence_of :id, :on => :update
- validates_presence_of :changeset_id, :version, :timestamp
- validates_uniqueness_of :id
- validates_inclusion_of :visible, :in => [true, false]
- validates_numericality_of :changeset_id, :version, :integer_only => true
- validates_numericality_of :id, :on => :update, :integer_only => true
- validates_associated :changeset
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :version, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :changeset_id, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :timestamp, :presence => true
+ validates :changeset, :associated => true
+ validates :visible, :inclusion => [true, false]
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }
belongs_to :way
- validates_presence_of :way
- validates_length_of :k, :maximum => 255, :allow_blank => true
- validates_uniqueness_of :k, :scope => :way_id
- validates_length_of :v, :maximum => 255, :allow_blank => true
+ validates :way, :presence => true, :associated => true
+ validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+ validates :k, :uniqueness => { :scope => :way_id }
end
-module ActiveRecord
- module Validations
- module ClassMethods
- ##
- # validation method to be included like any other validations methods
- # in the models definitions. this one checks that the named attribute
- # is a valid UTF-8 format string.
- def validates_as_utf8(*attrs)
- validates_each(attrs) do |record, attr, value|
- record.errors.add(attr, " is invalid UTF-8") unless UTF8.valid? value
- end
- end
- end
+##
+# validation method to be included like any other validations methods
+# in the models definitions. this one checks that the named attribute
+# is a valid UTF-8 format string.
+class Utf8Validator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ record.errors.add(attribute, " is invalid UTF-8") unless UTF8.valid? value
end
end