mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
Dont allow following of own sites
This commit is contained in:
parent
9e5d8d044f
commit
7a50bed7d3
1 changed files with 14 additions and 3 deletions
|
@ -345,6 +345,19 @@ class Site < Sequel::Model
|
||||||
followings_dataset.select(:follows__id).filter(site_id: site.id).first ? true : false
|
followings_dataset.select(:follows__id).filter(site_id: site.id).first ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def account_sites_follow?(site)
|
||||||
|
account_site_ids = account_sites_dataset.select(:id).all.collect {|s| s.id}
|
||||||
|
return true if Follow.where(actioning_site_id: account_site_ids, site_id: site.id).count > 0
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_follow?(site)
|
||||||
|
return false if site.id == self.id # Do not follow yourself
|
||||||
|
return false if site.owned_by?(self) # Do not follow your own sites
|
||||||
|
# return false if account_sites_follow?(site) # Do not follow if any of your other sites follow
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def toggle_follow(site)
|
def toggle_follow(site)
|
||||||
if is_following? site
|
if is_following? site
|
||||||
DB.transaction do
|
DB.transaction do
|
||||||
|
@ -355,7 +368,7 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
return false if site.id == self.id # Do not follow yourself
|
return false unless can_follow?(site)
|
||||||
|
|
||||||
DB.transaction do
|
DB.transaction do
|
||||||
follow = add_following site_id: site.id
|
follow = add_following site_id: site.id
|
||||||
|
@ -925,8 +938,6 @@ class Site < Sequel::Model
|
||||||
!domain.blank? && !ssl_key.blank? && !ssl_cert.blank?
|
!domain.blank? && !ssl_key.blank? && !ssl_cert.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def sandboxed?
|
def sandboxed?
|
||||||
plan_type == 'free' && created_at > SANDBOX_TIME.ago
|
plan_type == 'free' && created_at > SANDBOX_TIME.ago
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue