Class: Unsakini::UserBoard

Inherits:
ApplicationRecord show all
Includes:
EncryptableModelConcern
Defined in:
app/models/unsakini/user_board.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EncryptableModelConcern

#encryptable_attributes

Class Method Details

.shared(is_shared) ⇒ Object

Returns user_boards where Board is ‘is_shared`

Parameters:

  • is_shared (Boolean)

    wether to return shared or not shared boards



33
34
35
36
# File 'app/models/unsakini/user_board.rb', line 33

def self.shared(is_shared)
  joins("LEFT JOIN #{Board.table_name} ON #{self.table_name}.board_id = #{Board.table_name}.id")
  .where("#{Board.table_name}.is_shared = ?", is_shared)
end

Instance Method Details

#nameObject



22
23
24
25
26
27
28
# File 'app/models/unsakini/user_board.rb', line 22

def name
  if !@name.nil?
    @name
  else
    self.board.name
  end
end

#name=(str) ⇒ Object



18
19
20
# File 'app/models/unsakini/user_board.rb', line 18

def name=(str)
  @name = str
end

#share(user_ids, new_key) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/unsakini/user_board.rb', line 38

def share(user_ids, new_key)
  ActiveRecord::Base.transaction do
    user_ids.each do |usr_id|
      UserBoard.new({
                      user_id: usr_id,
                      board_id: self.board_id,
                      encrypted_password: nil,
                      is_admin: false
      })
      .save!
    end
    self.board.is_shared = true
    self.encrypted_password = new_key
    self.save!
  end
  true

rescue
  self.errors[:base] << "Unable to share the this board"
  false
end