diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/node.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 24f3cd0..aa2f7f3 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -367,6 +367,22 @@ class Node < ApplicationRecord | |||
| 367 | .distinct | 367 | .distinct |
| 368 | end | 368 | end |
| 369 | 369 | ||
| 370 | def self.drafts_and_autosaves(current_user_id: nil) | ||
| 371 | scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL") | ||
| 372 | return scope.order("updated_at DESC") unless current_user_id | ||
| 373 | |||
| 374 | scope.order( | ||
| 375 | Arel.sql(sanitize_sql_array(["CASE WHEN locking_user_id = ? THEN 0 ELSE 1 END, updated_at DESC", current_user_id])) | ||
| 376 | ) | ||
| 377 | end | ||
| 378 | |||
| 379 | def self.recently_changed | ||
| 380 | where( | ||
| 381 | "nodes.updated_at < ? AND nodes.updated_at > ? AND nodes.parent_id IS NOT NULL", | ||
| 382 | Time.now, Time.now - 14.days | ||
| 383 | ) | ||
| 384 | end | ||
| 385 | |||
| 370 | protected | 386 | protected |
| 371 | def lock_for! current_user | 387 | def lock_for! current_user |
| 372 | self.lock_owner = current_user | 388 | self.lock_owner = current_user |
