Class: Share

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/share.rb

Instance Method Summary collapse

Instance Method Details

#addItems(items, share_permissions = nil) ⇒ Object

Add items to the share



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/share.rb', line 29

def addItems(items, share_permissions=nil)
  if items.kind_of?(Array)
    # Add each item to this share
    items.each do |i|
      shareItem = SharesItem.new(share_permissions)
      shareItem.item = i
      # Add the shares items in the share
      self.shares_items << shareItem
    end
  else
    shareItem = SharesItem.new(share_permissions)
    shareItem.item = items
    # Add the shares items in the share
    self.shares_items << shareItem
  end
end

#get_authorisations(item) ⇒ Object

Return the authorisations of the share for the item



17
18
19
20
21
22
23
24
25
26
# File 'app/models/share.rb', line 17

def get_authorisations(item)
  # If the item is the owner, he can do what he want !
  if self.owner == item
    return true
  elsif i = self.shares_items.where(item_id: item.id, item_type: item.class.base_class.to_s).first
    return {can_add: i.can_add, can_remove: i.can_remove}
  else
    return false
  end
end

#removeItems(items) ⇒ Object

Remove items to the share



47
48
49
50
51
52
53
54
55
56
# File 'app/models/share.rb', line 47

def removeItems(items)
  if items.kind_of?(Array)
    # Add each item to this share
    items.each do |item|
      self.shares_items.where(:item_id => item.id, :item_type => item.class.base_class.to_s).first.destroy
    end
  else
    self.shares_items.where(:item_id => items.id, :item_type => items.class.base_class.to_s).first.destroy
  end
end