libertree-model 0.9.13 → 0.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f26c40457eee333ca5e41f43641188d00fcb06d5c5f5eb9dcd9d3c65e262d89
4
- data.tar.gz: c8ccc4d3da0d8a7b804e9f985e234310139cd01a139812dea05ec5cee03da49b
3
+ metadata.gz: e5571a9aaefa5aabcc1a15a11bd9eac49a49aed6a16cdcb6ce33cf13706abe66
4
+ data.tar.gz: bac9a39c327eb71527c7473d655e91349d5275953fb2075567a723eb2f88a2f8
5
5
  SHA512:
6
- metadata.gz: 3ab95ddb06996c91860ae1cf44b121e565febe27263535080458d1cbddb173e99791ee135c4f4711528b16d3c04313b1f6a8465e0db4d055ee3b32b97f82ed35
7
- data.tar.gz: 29823f4307bfb836011b98413b05e911d3baea0ee885fab27d48659be14a4b776f348d4714302b8f5c0ccd25028fc485e654a9bf2e5b89fe5024028ec88df1cd
6
+ metadata.gz: 525a5546eb0f68a0d65521c9574926e70aee266a6a7088a3bfa1af1677b321dd42584a60bb1cd612e34542aa13cef407127e5e68ec6e1b33d746ccded4cb806c
7
+ data.tar.gz: 1b7aa3baeb1430d6805f55b72d3fdab9419c7c9e7e3047ea771837c75436db20b2e8cb527e30c8b63432104617fda86d5ca038f8f2c417298286d22bd78c8ac9
@@ -42,8 +42,13 @@ module Libertree
42
42
 
43
43
  def self.authenticate_db(creds)
44
44
  if creds['password_reset_code'].to_s
45
- account = Account.where(%{password_reset_code = ? AND NOW() <= password_reset_expiry},
46
- creds['password_reset_code'].to_s).first
45
+ account = Account.where(
46
+ Sequel.lit(
47
+ %{password_reset_code = ? AND NOW() <= password_reset_expiry},
48
+ creds['password_reset_code'].to_s
49
+ )
50
+ ).first
51
+
47
52
  if account
48
53
  return account
49
54
  end
@@ -286,7 +291,9 @@ module Libertree
286
291
  end
287
292
 
288
293
  def invitations_not_accepted
289
- Invitation.where("inviter_account_id = ? AND account_id IS NULL", self.id).order(:id).all
294
+ Invitation.where(
295
+ Sequel.lit("inviter_account_id = ? AND account_id IS NULL", self.id)
296
+ ).order(:id).all
290
297
  end
291
298
 
292
299
  def new_invitation
@@ -362,7 +369,10 @@ module Libertree
362
369
  # @return [Boolean] true iff password reset was successfully set up
363
370
  def self.set_up_password_reset_for(email)
364
371
  # TODO: Don't allow registration of accounts with the same email but different case
365
- account = self.where('LOWER(email) = ?', email.downcase).first
372
+ account = self.where(
373
+ Sequel.lit('LOWER(email) = ?', email.downcase)
374
+ ).first
375
+
366
376
  if account
367
377
  account.password_reset_code = SecureRandom.hex(16)
368
378
  account.password_reset_expiry = Time.now + 60 * 60
@@ -67,8 +67,13 @@ module Libertree
67
67
  def self.mark_seen_between(account, member_id)
68
68
  return if account.nil?
69
69
 
70
- self.where("from_member_id = ? AND to_member_id = ?", member_id.to_i, account.member.id).
71
- update(seen: true)
70
+ self.where(
71
+ Sequel.lit(
72
+ "from_member_id = ? AND to_member_id = ?",
73
+ member_id.to_i,
74
+ account.member.id
75
+ )
76
+ ).update(seen: true)
72
77
  end
73
78
  end
74
79
  end
@@ -9,10 +9,12 @@ module Libertree
9
9
  else
10
10
  dict = 'english'
11
11
  end
12
- self.where("(to_tsvector('simple', text) || to_tsvector('english', text)) @@ plainto_tsquery('#{dict}', ?)", q).
13
- reverse_order(:time_created).
14
- limit(limit.to_i).
15
- all
12
+
13
+ self.where(
14
+ Sequel.lit("(to_tsvector('simple', text) || to_tsvector('english', text)) @@ plainto_tsquery('#{dict}', ?)", q)
15
+ ).reverse_order(:time_created)
16
+ .limit(limit.to_i)
17
+ .all
16
18
  end
17
19
  end
18
20
  end
@@ -45,7 +45,12 @@ module Libertree
45
45
 
46
46
  # @return [Job] nil if no job was reserved
47
47
  def self.reserve(tasks)
48
- job = self.where("task IN ? AND pid IS NULL AND tries < #{MAX_TRIES} AND time_to_start <= NOW()", tasks).order(:time_to_start).limit(1).first
48
+ job = self.where(
49
+ Sequel.lit("task IN ? AND pid IS NULL AND tries < #{MAX_TRIES} AND time_to_start <= NOW()", tasks)
50
+ ).order(:time_to_start)
51
+ .limit(1)
52
+ .first
53
+
49
54
  return nil if job.nil?
50
55
 
51
56
  self.where({ id: job.id, pid: nil }).
@@ -72,20 +77,22 @@ module Libertree
72
77
  params = args[1..-1]
73
78
 
74
79
  self.where(
75
- query + %{
76
- AND time_finished IS NULL
77
- AND tries < ?
78
- },
79
- *params,
80
- MAX_TRIES
80
+ Sequel.lit(
81
+ query + %{
82
+ AND time_finished IS NULL
83
+ AND tries < ?
84
+ },
85
+ *params,
86
+ MAX_TRIES
87
+ )
81
88
  )
82
89
  end
83
90
 
84
91
  def self.unfinished(task=nil)
85
92
  if task
86
- self.where("task = ? AND time_finished IS NULL", task).all
93
+ self.where(Sequel.lit("task = ? AND time_finished IS NULL", task)).all
87
94
  else
88
- self.where("time_finished IS NULL").all
95
+ self.where(Sequel.lit("time_finished IS NULL")).all
89
96
  end
90
97
  end
91
98
  end
@@ -80,18 +80,23 @@ module Libertree
80
80
  if local
81
81
  self.qualify.
82
82
  join(:accounts, :id=>:account_id).
83
- where(:accounts__username => username).
83
+ where(Sequel.qualify(:accounts, :username) => username).
84
84
  limit(1).
85
85
  first
86
86
  else
87
87
  # TODO: servers.name_given is no longer used. Remove it after
88
88
  # migrating user rivers/contact lists etc.
89
- self.qualify.
90
- join(:servers, :id=>:server_id).
91
- where(:members__username => username).
92
- where(Sequel.or(:servers__domain => host, :servers__name_given => host)).
93
- limit(1).
94
- first
89
+ self.qualify
90
+ .join(:servers, :id=>:server_id)
91
+ .where(Sequel.qualify(:members, :username) => username)
92
+ .where(
93
+ Sequel.or(
94
+ Sequel.qualify(:servers, :domain) => host,
95
+ Sequel.qualify(:servers, :name_given) => host
96
+ )
97
+ )
98
+ .limit(1)
99
+ .first
95
100
  end
96
101
  end
97
102
 
@@ -100,7 +105,7 @@ module Libertree
100
105
  def self.with_display_name(name)
101
106
  self.qualify.
102
107
  join(:profiles, :member_id=>:id).
103
- where(:profiles__name_display => name).
108
+ where(Sequel.qualify(:profiles, :name_display) => name).
104
109
  limit(1).
105
110
  first
106
111
  end
@@ -7,6 +7,7 @@ module Libertree
7
7
  :subscribed ]
8
8
 
9
9
  many_to_one :node
10
+ set_primary_key :id
10
11
 
11
12
  def self.for(jid_or_host)
12
13
  return self unless jid_or_host
@@ -14,7 +15,7 @@ module Libertree
14
15
  if jid_or_host.include?('@')
15
16
  self.where(jid: jid_or_host)
16
17
  else
17
- host_pattern = self.where.escape_like(jid_or_host.to_s)
18
+ host_pattern = self.where(Sequel.lit('true')).escape_like(jid_or_host.to_s)
18
19
  self.where(Sequel.like(:jid, "%@#{host_pattern}"))
19
20
  end
20
21
  end
@@ -46,8 +46,14 @@ module Libertree
46
46
  end
47
47
 
48
48
  def self.mark_seen_for_account_and_message(account, message)
49
- self.where("account_id = ? AND data = ?", account.id, %|{"type":"message","message_id":#{message.id}}|).
50
- update(seen: true)
49
+ self.where(
50
+ Sequel.lit(
51
+ "account_id = ? AND data = ?",
52
+ account.id,
53
+ %|{"type":"message","message_id":#{message.id}}|
54
+ )
55
+ ).update(seen: true)
56
+
51
57
  account.dirty
52
58
  end
53
59
 
@@ -96,7 +96,13 @@ module Libertree
96
96
  def mark_as_unread_by_all( options = {} )
97
97
  except_accounts = options.fetch(:except, [])
98
98
  if except_accounts.any?
99
- DB.dbh[:posts_read].where('post_id = ? AND NOT account_id IN ?', self.id, except_accounts.map(&:id)).delete
99
+ DB.dbh[:posts_read].where(
100
+ Sequel.lit(
101
+ 'post_id = ? AND NOT account_id IN ?',
102
+ self.id,
103
+ except_accounts.map(&:id)
104
+ )
105
+ ).delete
100
106
  else
101
107
  DB.dbh[ "DELETE FROM posts_read WHERE post_id = ?", self.id ].get
102
108
  end
@@ -351,47 +357,47 @@ module Libertree
351
357
  posts.
352
358
  qualify.
353
359
  left_outer_join(:posts_hidden,
354
- :posts_hidden__post_id => :posts__id,
355
- :posts_hidden__account_id => account.id).
356
- where(:posts_hidden__post_id => nil)
360
+ Sequel.qualify(:posts_hidden, :post_id) => Sequel.qualify(:posts, :id),
361
+ Sequel.qualify(:posts_hidden, :account_id) => account.id).
362
+ where(Sequel.qualify(:posts_hidden, :post_id) => nil)
357
363
  end
358
364
 
359
365
  def self.read_by(account, posts=self)
360
366
  posts.
361
367
  qualify.
362
368
  join(:posts_read,
363
- :posts_read__post_id => :posts__id,
364
- :posts_read__account_id => account.id)
369
+ Sequel.qualify(:posts_read, :post_id) => Sequel.qualify(:posts, :id),
370
+ Sequel.qualify(:posts_read, :account_id) => account.id)
365
371
  end
366
372
 
367
373
  def self.unread_by(account, posts=self)
368
374
  posts.
369
375
  qualify.
370
376
  left_outer_join(:posts_read,
371
- :posts_read__post_id => :posts__id,
372
- :posts_read__account_id => account.id).
373
- where(:posts_read__post_id => nil)
377
+ Sequel.qualify(:posts_read, :post_id) => Sequel.qualify(:posts, :id),
378
+ Sequel.qualify(:posts_read, :account_id) => account.id).
379
+ where(Sequel.qualify(:posts_read, :post_id) => nil)
374
380
  end
375
381
 
376
382
  def self.liked_by(member, posts=self)
377
383
  posts.
378
384
  qualify.
379
385
  join(:post_likes,
380
- :post_likes__post_id => :posts__id,
381
- :post_likes__member_id => member.id)
386
+ Sequel.qualify(:post_likes, :post_id) => Sequel.qualify(:posts, :id),
387
+ Sequel.qualify(:post_likes, :member_id) => member.id)
382
388
  end
383
389
 
384
390
  def self.without_liked_by(member, posts=self)
385
391
  posts.
386
392
  qualify.
387
393
  join(:post_likes,
388
- :post_likes__post_id => :posts__id,
389
- :post_likes__member_id => member.id)
394
+ Sequel.qualify(:post_likes, :post_id) => Sequel.qualify(:posts, :id),
395
+ Sequel.qualify(:post_likes, :member_id) => member.id)
390
396
  end
391
397
 
392
398
  def self.commented_on_by(member, posts=self)
393
399
  posts.
394
- where(:posts__id => Comment.
400
+ where(Sequel.qualify(:posts, :id) => Comment.
395
401
  select(:post_id).
396
402
  distinct(:post_id).
397
403
  where(:member_id => member.id))
@@ -399,7 +405,7 @@ module Libertree
399
405
 
400
406
  def self.without_commented_on_by(member, posts=self)
401
407
  posts.
402
- exclude(:posts__id => Comment.
408
+ exclude(Sequel.qualify(:posts, :id) => Comment.
403
409
  select(:post_id).
404
410
  distinct(:post_id).
405
411
  where(:member_id => member.id))
@@ -409,17 +415,17 @@ module Libertree
409
415
  posts.
410
416
  qualify.
411
417
  join(:post_subscriptions,
412
- :post_subscriptions__post_id => :posts__id,
413
- :post_subscriptions__account_id => account.id)
418
+ Sequel.qualify(:post_subscriptions, :post_id) => Sequel.qualify(:posts, :id),
419
+ Sequel.qualify(:post_subscriptions, :account_id) => account.id)
414
420
  end
415
421
 
416
422
  def self.without_subscribed_to_by(account, posts=self)
417
423
  posts.
418
424
  qualify.
419
425
  left_outer_join(:post_subscriptions,
420
- :post_subscriptions__post_id => :posts__id,
421
- :post_subscriptions__account_id => account.id).
422
- where(:post_subscriptions__post_id => nil)
426
+ Sequel.qualify(:post_subscriptions, :post_id) => Sequel.qualify(:posts, :id),
427
+ Sequel.qualify(:post_subscriptions, :account_id) => account.id).
428
+ where(Sequel.qualify(:post_subscriptions, :post_id) => nil)
423
429
  end
424
430
 
425
431
  def self.filter_by_query(parsed_query, account, posts=self)
@@ -518,13 +524,19 @@ module Libertree
518
524
 
519
525
  # filter by simple terms first to avoid having to check so many posts
520
526
  # TODO: prevent empty arguments to to_tsquery
521
- posts = posts.where(%{to_tsvector('simple', text)
522
- @@ (to_tsquery('simple', ?)
523
- && to_tsquery('simple', ?)
524
- && to_tsquery('simple', ?))},
525
- words[:negations].map{|w| "!#{w}" }.join(' & '),
526
- words[:requirements].join(' & '),
527
- words[:regular].join(' | '))
527
+ posts = posts.where(
528
+ Sequel.lit(
529
+ %{
530
+ to_tsvector('simple', text)
531
+ @@ (to_tsquery('simple', ?)
532
+ && to_tsquery('simple', ?)
533
+ && to_tsquery('simple', ?))
534
+ },
535
+ words[:negations].map{|w| "!#{w}" }.join(' & '),
536
+ words[:requirements].join(' & '),
537
+ words[:regular].join(' | ')
538
+ )
539
+ )
528
540
  end
529
541
 
530
542
  { 'visibility' => :visibility,
@@ -618,14 +630,16 @@ module Libertree
618
630
 
619
631
  get_comments = lambda do
620
632
  comments = Comment.on_post(post, viewing_account: viewing_account)
621
- comment_likes = CommentLike.where('comment_id IN ?', comments.map(&:id)).reduce({}) do |hash, like|
633
+ comment_likes = CommentLike.where(
634
+ Sequel.lit('comment_id IN ?', comments.map(&:id))
635
+ ).reduce({}) { |hash, like|
622
636
  if hash[like.comment_id]
623
637
  hash[like.comment_id] << like
624
638
  else
625
639
  hash[like.comment_id] = [like]
626
640
  end
627
641
  hash
628
- end
642
+ }
629
643
 
630
644
  comments.map do |comment|
631
645
  likes = if comment_likes[comment.id]
@@ -699,9 +713,14 @@ module Libertree
699
713
  end
700
714
 
701
715
  def pools_by_member(member_id)
702
- Libertree::Model::Pool.qualify.
703
- join(:pools_posts, :pools_posts__pool_id => :pools__id).
704
- where(pools_posts__post_id: self.id, pools__member_id: member_id)
716
+ Libertree::Model::Pool.qualify
717
+ .join(
718
+ :pools_posts,
719
+ Sequel.qualify(:pools_posts, :pool_id) => Sequel.qualify(:pools, :id)
720
+ ).where(
721
+ Sequel.qualify(:pools_posts, :post_id) => self.id,
722
+ Sequel.qualify(:pools, :member_id) => member_id
723
+ )
705
724
  end
706
725
 
707
726
  def update_collection_status_for_member(member_id, pool_ids)
@@ -18,7 +18,11 @@ module Libertree
18
18
  end
19
19
 
20
20
  def self.search(query)
21
- self.where("(to_tsvector('simple', description) || to_tsvector('english', description)) @@ plainto_tsquery(?)", query).or("name_display ILIKE '%' || ? || '%'", query)
21
+ self.where(
22
+ Sequel.lit("(to_tsvector('simple', description) || to_tsvector('english', description)) @@ plainto_tsquery(?)", query)
23
+ ).or(
24
+ Sequel.lit("name_display ILIKE '%' || ? || '%'", query)
25
+ )
22
26
  end
23
27
  end
24
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libertree-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.13
4
+ version: 0.9.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pistos
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-13 00:00:00.000000000 Z
12
+ date: 2020-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-oembed
@@ -57,16 +57,16 @@ dependencies:
57
57
  name: sequel
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "<"
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '5'
62
+ version: 5.34.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "<"
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '5'
69
+ version: 5.34.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bcrypt-ruby
72
72
  requirement: !ruby/object:Gem::Requirement