Skip to content

Commit

Permalink
Add individual edit white & blacklisting.
Browse files Browse the repository at this point in the history
A single edit is an object + version pair.  Object is designated with
the initial character of "node", "way" or "relation" followed by the ID
in decimal.  The white/black lists contain one object+version string on
each line, e.g.

n456653v2
w123456v3
  • Loading branch information
balrog-kun committed Jul 10, 2012
1 parent 0b6b86e commit edc174f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
32 changes: 30 additions & 2 deletions change_bot.rb
Expand Up @@ -27,6 +27,30 @@ def odbl_clean_versions
version_is_clean.reverse.map {|flag| global = flag && global}.reverse
end

def whitelisted_versions
obj = @versions.first
id_str = if obj.class == OSM::Node
'n'
elsif obj.class == OSM::Way
'w'
else
'r'
end + obj.element_id.to_s + 'v'
@versions.map {|v| @db.edit_whitelist.include?(id_str + v.version.to_s)}
end

def blacklisted_versions
obj = @versions.first
id_str = if obj.class == OSM::Node
'n'
elsif obj.class == OSM::Way
'w'
else
'r'
end + obj.element_id.to_s + 'v'
@versions.map {|v| @db.edit_blacklist.include?(id_str + v.version.to_s)}
end

def actions
accepted_versions = @versions.map {|obj| changeset_is_accepted? obj.changeset_id}

Expand All @@ -42,7 +66,7 @@ def actions
omit_tags = []
omit_tags = ["multipolygon", "route", "site", "restriction", "boundary"].map{|v| ["type", v]} if base_obj.class == OSM::Relation

@versions.zip(odbl_clean_versions, accepted_versions).each do |obj,is_odbl_clean,accepted|
@versions.zip(odbl_clean_versions, accepted_versions, whitelisted_versions, blacklisted_versions).each do |obj,is_odbl_clean,accepted,is_whitelisted,is_blacklisted|
# deletions are always "clean", and we consider them to
# have no tags and the "version zero" geometry. what
# happens after that may be a revert to a previous version.
Expand All @@ -61,8 +85,12 @@ def actions
# clean, and we try to enumerate them here.
status = if is_odbl_clean
:odbl_clean
elsif is_blacklisted
:unclean
elsif accepted
:acceptor_edit
elsif is_whitelisted
:whitelisted_version
elsif tags_patch.empty? and geom_patch.empty?
:empty
elsif tags_patch.trivial? and geom_patch.empty?
Expand Down Expand Up @@ -124,7 +152,7 @@ def actions
#not (geom_patch.only_deletes? and tags_patch.only_deletes?))
visibility = ((status == :unclean) ?
tags_patch.only_deletes? && geom_patch.only_deletes? :
new_tags != base_obj.tags || new_geom != base_obj.geom || status == :acceptor_edit || status == :empty)
new_tags != base_obj.tags || new_geom != base_obj.geom || status == :acceptor_edit || status == :whitelisted_version || status == :empty)
xactions << Redact[obj.class, obj.element_id, obj.version, visibility ? :visible : :hidden]
end

Expand Down
4 changes: 4 additions & 0 deletions db.rb
Expand Up @@ -6,6 +6,7 @@ class DB
def metaclass; class << self; self; end; end

#attr_reader :changesets, :nodes, :ways, :relations
attr_accessor :edit_whitelist, :edit_blacklist

def initialize(options = {})
# define a set of accessors for changesets, nodes, ways and
Expand All @@ -29,6 +30,9 @@ def initialize(options = {})
end

@exclusions = Hash.new

@edit_whitelist = Array.new
@edit_blacklist = Array.new
end

def exclude(klass, ids)
Expand Down
6 changes: 6 additions & 0 deletions pg_db.rb
Expand Up @@ -67,6 +67,12 @@ def initialize(dbconn)

# An array of whitelisted users
@user_whitelist = File.open("users_whitelist.txt").map{ |l| l.to_i }

# An array of blacklisted edits
@edit_blacklist = File.open("edits_blacklist.txt").read.split("\n")

# An array of whitelisted edits
@edit_whitelist = File.open("edits_whitelist.txt").read.split("\n")
end

def node(id, current = false)
Expand Down

0 comments on commit edc174f

Please sign in to comment.