skip_before_action :verify_authenticity_token
before_action :check_api_writable
+ # AMF Controller implements its own authentication and authorization checks
+ # completely independently of the rest of the codebase, so best just to let
+ # it keep doing its own thing.
+ skip_authorization_check
+
# Main AMF handlers: process the raw AMF string (using AMF library) and
# calls each action (private method) accordingly.
return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
query = Trace.visible_to(user)
- query = if searchterm.to_i > 0
+ query = if searchterm.to_i.positive?
query.where(:id => searchterm.to_i)
else
query.where("MATCH(name) AGAINST (?)", searchterm).limit(21)
def findrelations(searchterm)
rels = []
- if searchterm.to_i > 0
+ if searchterm.to_i.positive?
rel = Relation.where(:id => searchterm.to_i).first
- rels.push([rel.id, rel.tags, rel.members, rel.version]) if rel && rel.visible
+ rels.push([rel.id, rel.tags, rel.members, rel.version]) if rel&.visible
else
RelationTag.where("v like ?", "%#{searchterm}%").limit(11).each do |t|
rels.push([t.relation.id, t.relation.tags, t.relation.members, t.relation.version]) if t.relation.visible
relation = nil
Relation.transaction do
# create a new relation, or find the existing one
- relation = Relation.find(relid) if relid > 0
+ relation = Relation.find(relid) if relid.positive?
# We always need a new node, based on the data that has been sent to us
new_relation = Relation.new
typedmembers = []
members.each do |m|
mid = m[1].to_i
- if mid < 0
+ if mid.negative?
mid = renumberednodes[mid] if m[0] == "Node"
mid = renumberedways[mid] if m[0] == "Way"
end
node = nil
new_node = nil
Node.transaction do
- if id > 0
+ if id.positive?
begin
node = Node.find(id)
rescue ActiveRecord::RecordNotFound
# in the +tags+ hash.
def strip_non_xml_chars(tags)
new_tags = {}
- unless tags.nil?
- tags.each do |k, v|
- new_k = k.delete "\000-\037\ufffe\uffff", "^\011\012\015"
- new_v = v.delete "\000-\037\ufffe\uffff", "^\011\012\015"
- new_tags[new_k] = new_v
- end
+ tags&.each do |k, v|
+ new_k = k.delete "\000-\037\ufffe\uffff", "^\011\012\015"
+ new_v = v.delete "\000-\037\ufffe\uffff", "^\011\012\015"
+ new_tags[new_k] = new_v
end
new_tags
end