Merge branch 'master' into moderation

This commit is contained in:
Andy Allan 2018-02-28 15:46:25 +08:00
commit 424b6ef1cf
273 changed files with 45853 additions and 25111 deletions

View file

@ -55,9 +55,6 @@ class Changeset < ActiveRecord::Base
before_save :update_closed_at
# over-expansion factor to use when updating the bounding box
EXPAND = 0.1
# maximum number of elements allowed in a changeset
MAX_ELEMENTS = 10000
@ -127,12 +124,9 @@ class Changeset < ActiveRecord::Base
end
##
# expand the bounding box to include the given bounding box. also,
# expand a little bit more in the direction of the expansion, so that
# further expansions may be unnecessary. this is an optimisation
# suggested on the wiki page by kleptog.
# expand the bounding box to include the given bounding box.
def update_bbox!(bbox_update)
bbox.expand!(bbox_update, EXPAND)
bbox.expand!(bbox_update)
# update active record. rails 2.1's dirty handling should take care of
# whether this object needs saving or not.
@ -141,8 +135,7 @@ class Changeset < ActiveRecord::Base
##
# the number of elements is also passed in so that we can ensure that
# a single changeset doesn't contain too many elements. this, of course,
# destroys the optimisation described in the bbox method above.
# a single changeset doesn't contain too many elements.
def add_changes!(elements)
self.num_changes += elements
end

View file

@ -9,6 +9,7 @@ class Notifier < ActionMailer::Base
def signup_confirm(user, token)
with_recipient_locale user do
@url = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "user", :action => "confirm",
:display_name => user.display_name,
:confirm_string => token.token)
@ -22,6 +23,7 @@ class Notifier < ActionMailer::Base
with_recipient_locale user do
@address = user.new_email
@url = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "user", :action => "confirm_email",
:confirm_string => token.token)
@ -33,6 +35,7 @@ class Notifier < ActionMailer::Base
def lost_password(user, token)
with_recipient_locale user do
@url = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "user", :action => "reset_password",
:token => token.token)
@ -73,9 +76,11 @@ class Notifier < ActionMailer::Base
@text = message.body
@title = message.title
@readurl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "message", :action => "read",
:message_id => message.id)
@replyurl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "message", :action => "reply",
:message_id => message.id)
@author = @from_user
@ -95,18 +100,21 @@ class Notifier < ActionMailer::Base
@text = comment.body
@title = comment.diary_entry.title
@readurl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "diary_entry",
:action => "view",
:display_name => comment.diary_entry.user.display_name,
:id => comment.diary_entry.id,
:anchor => "comment#{comment.id}")
@commenturl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "diary_entry",
:action => "view",
:display_name => comment.diary_entry.user.display_name,
:id => comment.diary_entry.id,
:anchor => "newcomment")
@replyurl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "message",
:action => "new",
:display_name => comment.user.display_name,
@ -125,9 +133,11 @@ class Notifier < ActionMailer::Base
with_recipient_locale friend.befriendee do
@friend = friend
@viewurl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "user", :action => "view",
:display_name => @friend.befriender.display_name)
@friendurl = url_for(:host => SERVER_URL,
:protocol => SERVER_PROTOCOL,
:controller => "user", :action => "make_friend",
:display_name => @friend.befriender.display_name)
@author = @friend.befriender.display_name

View file

@ -182,9 +182,7 @@ class Relation < ActiveRecord::Base
end
def delete_with_history!(new_relation, user)
unless visible
raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id)
end
raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id) unless visible
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
@ -208,9 +206,7 @@ class Relation < ActiveRecord::Base
Relation.transaction do
lock!
check_consistency(self, new_relation, user)
unless new_relation.preconditions_ok?(members)
raise OSM::APIPreconditionFailedError, "Cannot update relation #{id}: data or member data is invalid."
end
raise OSM::APIPreconditionFailedError, "Cannot update relation #{id}: data or member data is invalid." unless new_relation.preconditions_ok?(members)
self.changeset_id = new_relation.changeset_id
self.changeset = new_relation.changeset
self.tags = new_relation.tags
@ -222,9 +218,7 @@ class Relation < ActiveRecord::Base
def create_with_history(user)
check_create_consistency(self, user)
unless preconditions_ok?
raise OSM::APIPreconditionFailedError, "Cannot create relation: data or member data is invalid."
end
raise OSM::APIPreconditionFailedError, "Cannot create relation: data or member data is invalid." unless preconditions_ok?
self.version = 0
self.visible = true
save_with_history!
@ -259,9 +253,7 @@ class Relation < ActiveRecord::Base
element = model.lock("for share").find_by(:id => m[1])
# and check that it is OK to use.
unless element && element.visible? && element.preconditions_ok?
raise OSM::APIPreconditionFailedError, "Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}"
end
raise OSM::APIPreconditionFailedError, "Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}" unless element && element.visible? && element.preconditions_ok?
hash[m[1]] = true
end

View file

@ -283,9 +283,7 @@ class User < ActiveRecord::Base
##
# perform a spam check on a user
def spam_check
if status == "active" && spam_score > SPAM_THRESHOLD
update(:status => "suspended")
end
update(:status => "suspended") if status == "active" && spam_score > SPAM_THRESHOLD
end
##

View file

@ -120,14 +120,10 @@ class Way < ActiveRecord::Base
way_nodes.each do |nd|
if visible_nodes
# if there is a list of visible nodes then use that to weed out deleted nodes
if visible_nodes[nd.node_id]
ordered_nodes[nd.sequence_id] = nd.node_id.to_s
end
ordered_nodes[nd.sequence_id] = nd.node_id.to_s if visible_nodes[nd.node_id]
else
# otherwise, manually go to the db to check things
if nd.node && nd.node.visible?
ordered_nodes[nd.sequence_id] = nd.node_id.to_s
end
ordered_nodes[nd.sequence_id] = nd.node_id.to_s if nd.node && nd.node.visible?
end
end
@ -184,9 +180,7 @@ class Way < ActiveRecord::Base
Way.transaction do
lock!
check_consistency(self, new_way, user)
unless new_way.preconditions_ok?(nds)
raise OSM::APIPreconditionFailedError, "Cannot update way #{id}: data is invalid."
end
raise OSM::APIPreconditionFailedError, "Cannot update way #{id}: data is invalid." unless new_way.preconditions_ok?(nds)
self.changeset_id = new_way.changeset_id
self.changeset = new_way.changeset
@ -199,9 +193,7 @@ class Way < ActiveRecord::Base
def create_with_history(user)
check_create_consistency(self, user)
unless preconditions_ok?
raise OSM::APIPreconditionFailedError, "Cannot create way: data is invalid."
end
raise OSM::APIPreconditionFailedError, "Cannot create way: data is invalid." unless preconditions_ok?
self.version = 0
self.visible = true
save_with_history!
@ -209,9 +201,7 @@ class Way < ActiveRecord::Base
def preconditions_ok?(old_nodes = [])
return false if nds.empty?
if nds.length > MAX_NUMBER_OF_WAY_NODES
raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES)
end
raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES) if nds.length > MAX_NUMBER_OF_WAY_NODES
# check only the new nodes, for efficiency - old nodes having been checked last time and can't
# be deleted when they're in-use.