Class: GroupModelMigration

Inherits:
Migration show all
Defined in:
lib/yodel/models/migrations/04_group_model.rb

Class Method Summary collapse

Methods inherited from Migration

copy_missing_migrations_for_all_sites, copy_missing_migrations_for_site, inherited, run_migrations, run_migrations_for_all_sites

Class Method Details

.down(site) ⇒ Object



55
56
57
58
59
60
# File 'lib/yodel/models/migrations/04_group_model.rb', line 55

def self.down(site)
  site.groups.destroy
  site.owner_groups.destroy
  site.noone_groups.destroy
  site.guest_groups.destroy
end

.up(site) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yodel/models/migrations/04_group_model.rb', line 2

def self.up(site)
  site.records.create_model :groups do |groups|
    add_field :name, :string, validations: {required: {}}
    add_many  :users, store: false
    groups.icon = '/admin/images/group_icon.png'
    groups.record_class_name = 'Group'
  end
  site.reload
  
  # a special singleton group representing an 'owner' of a record
  site.groups.create_model :owner_groups do |group|
    group.record_class_name = 'OwnerGroup'
  end
  site.reload
  
  # a special singleton group representing no one
  site.groups.create_model :noone_groups do |group|
    group.record_class_name = 'NooneGroup'
  end
  site.reload
  
  # a special singleton group representing 'everyone'
  site.groups.create_model :guest_groups do |group|
    group.record_class_name = 'GuestsGroup'
  end
  site.reload
  
  
  # permissions are based on a hierarchy of groups. branches are permitted.
  noone = site.noone_groups.new(name: 'No One')
  noone.save
  
  devs = site.groups.new(name: 'Developers')
  devs.parent = noone
  devs.save
  
  admins = site.groups.new(name: 'Administrators')
  admins.parent = devs
  admins.save
  
  owner = site.owner_groups.new(name: 'Owner')
  owner.parent = admins
  owner.save
  
  users = site.groups.new(name: 'Users')
  users.parent = owner
  users.save
  
  guests = site.guest_groups.new(name: 'Guests')
  guests.parent = users
  guests.save
end