mirror of
https://github.com/neocities/neocities.git
synced 2025-08-06 09:34:57 +02:00
blocking, tag fixes
This commit is contained in:
parent
e546b22797
commit
447f654435
5 changed files with 125 additions and 13 deletions
|
@ -58,6 +58,7 @@ class Site < Sequel::Model
|
|||
|
||||
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62', '348x205']
|
||||
THUMBNAIL_RESOLUTIONS = ['105x63', '90x63']
|
||||
TAG_LENGTH_MAX = 25
|
||||
|
||||
many_to_one :server
|
||||
|
||||
|
@ -195,6 +196,37 @@ class Site < Sequel::Model
|
|||
}
|
||||
end
|
||||
|
||||
def follows_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
|
||||
def followings_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
|
||||
def events_dataset
|
||||
super.where(Sequel.~(site_id: blocking_site_ids))
|
||||
.where(Sequel.~(actioning_site_id: blocking_site_ids))
|
||||
end
|
||||
|
||||
def blocking_site_ids
|
||||
@blocking_site_ids ||= blockings_dataset.select(:site_id).all.collect {|s| s.site_id}
|
||||
end
|
||||
|
||||
def block!(site)
|
||||
block = blockings_dataset.filter(site_id: site.id).first
|
||||
DB.transaction do
|
||||
add_blocking site: site
|
||||
end
|
||||
end
|
||||
|
||||
def is_blocking?(site)
|
||||
@blockings ||= blockings
|
||||
!@blockings.select {|b| b.site_id == site.id}.empty?
|
||||
end
|
||||
|
||||
def self.valid_filename?(filename)
|
||||
return false if sanitize_filename(filename) != filename
|
||||
true
|
||||
|
@ -370,12 +402,17 @@ class Site < Sequel::Model
|
|||
break
|
||||
end
|
||||
|
||||
if tag.length > Tag::NAME_LENGTH_MAX
|
||||
errors.add :tags, "Tag \"#{tag}\" cannot be longer than #{Tag::NAME_LENGTH_MAX} characters."
|
||||
break
|
||||
end
|
||||
|
||||
if tag.match(/ /)
|
||||
errors.add :tags, "Tag \"#{tag}\" cannot have more than one space between words."
|
||||
break
|
||||
end
|
||||
|
||||
if tag.split(' ').length > 2
|
||||
if tag.split(' ').length > Tag::NAME_WORDS_MAX
|
||||
errors.add :tags, "Tag \"#{tag}\" cannot be more than two words."
|
||||
break
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class Tag < Sequel::Model
|
||||
NAME_LENGTH_MAX = 25
|
||||
NAME_WORDS_MAX = 2
|
||||
many_to_many :sites
|
||||
|
||||
def before_create
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue