Class: PostLocker

Inherits:
Object
  • Object
show all
Defined in:
lib/post_locker.rb

Instance Method Summary collapse

Constructor Details

#initialize(post, user) ⇒ PostLocker

Returns a new instance of PostLocker.



4
5
6
# File 'lib/post_locker.rb', line 4

def initialize(post, user)
  @post, @user = post, user
end

Instance Method Details

#lockObject



8
9
10
11
12
13
14
15
# File 'lib/post_locker.rb', line 8

def lock
  Guardian.new(@user).ensure_can_lock_post!(@post)

  Post.transaction do
    @post.update_column(:locked_by_id, @user.id)
    StaffActionLogger.new(@user).log_post_lock(@post, locked: true)
  end
end

#unlockObject



17
18
19
20
21
22
23
24
# File 'lib/post_locker.rb', line 17

def unlock
  Guardian.new(@user).ensure_can_lock_post!(@post)

  Post.transaction do
    @post.update_column(:locked_by_id, nil)
    StaffActionLogger.new(@user).log_post_lock(@post, locked: false)
  end
end