2012-04-19 20:45:50 +01:00
|
|
|
class ReservedNameValidator < ActiveModel::EachValidator
|
|
|
|
RESERVED_NAMES = %w{
|
2013-05-06 18:50:16 +01:00
|
|
|
about account add admin administrator api autocomplete_group_uname
|
2012-04-19 20:45:50 +01:00
|
|
|
app apps archive archives auth
|
|
|
|
blog
|
2013-04-08 10:24:17 +01:00
|
|
|
config connect contact create commit commits
|
2013-05-06 18:42:00 +01:00
|
|
|
dashboard delete direct_messages download downloads
|
2012-04-19 20:45:50 +01:00
|
|
|
edit email
|
|
|
|
faq favorites feed feeds follow followers following
|
|
|
|
help home
|
|
|
|
invitations invite
|
|
|
|
jobs
|
|
|
|
login log-in log_in logout log-out log_out logs
|
|
|
|
map maps
|
2013-04-08 10:24:17 +01:00
|
|
|
new none
|
2012-04-19 20:45:50 +01:00
|
|
|
oauth oauth_clients openid
|
|
|
|
privacy
|
|
|
|
register remove replies rss root
|
|
|
|
save search sessions settings
|
|
|
|
signup sign-up sign_up signin sign-in sign_in signout sign-out sign_out
|
|
|
|
sitemap ssl subscribe
|
2013-04-08 10:24:17 +01:00
|
|
|
teams terms test tour trends tree
|
2013-05-06 18:50:16 +01:00
|
|
|
unfollow unsubscribe upload uploads url user
|
2012-04-19 20:45:50 +01:00
|
|
|
widget widgets wiki
|
|
|
|
xfn xmpp
|
2012-04-23 21:55:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def reserved_names
|
|
|
|
@reserved_names ||= RESERVED_NAMES +
|
|
|
|
Rails.application.routes.routes.map{|r| r.path.spec.to_s.match(/^\/([\w-]+)/)[1] rescue nil}.uniq.compact # current routes
|
|
|
|
end
|
2012-04-19 20:45:50 +01:00
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
2012-05-02 10:18:07 +01:00
|
|
|
if reserved_names.include?(value.to_s.downcase)
|
2014-01-21 04:51:49 +00:00
|
|
|
record.errors.add(attribute, :exclusion, options.merge(value: value))
|
2012-04-19 20:45:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|