Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
lib/app/models/ability.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Ability

Returns a new instance of Ability.



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/app/models/ability.rb', line 4

def initialize(user)
  
  #
  # signed in user
  #
  unless user.blank?
    
    can [ :create, :new ], Gallery
    can [ :edit, :update, :destroy_photo, :show, :show_long ], Gallery do |g|
      g.user == user
    end

    can [ :new ], Message

    can [ :upload, :driver, :set_profile_photo, :new_profile_photo ], Photo
    can [ :move, :edit, :update, :show ], Photo do |photo|
      photo.user == user
    end
    can [ :show ], Photo do |photo|
      photo.viewer_ids.include? user.id || user == photo.user
    end
    can [ :destroy ], Photo do |photo|
      if photo.user == user
        if photo.gallery.blank?
          true
        elsif photo.gallery.is_anonymous
          false
        else
          true
        end
      else
        false
      end
    end

    can [ :new, :create, :search, :index, :my_index ], Report
    can [ :edit, :update, :show, :delete ], Report do |r|
      r.user == user
    end

    can [ :newsitems_new, :newsitems_create ], Site
    
    can [ :organizer, :photos, :new_profile, :create_profile, :edit_profile, :update_profile ], User
    can [ :edit, :update, :update_profile ], User do |uu|
      uu == user
    end

    can [ :new ], Venue

    can [ :new, :create ], Video

    # manager, group_id 1
    #
    if user[:group_id] <= 2        
      can [ :manage ], CitiesUser
      can [ :manage ], City
      can [ :manage ], Country
      can [ :manage ], Day
      can [ :manage ], Event
      can [ :manage ], Feature
      can [ :manage ], Gallery
      can [ :manage ], Newsitem
      can [ :manage ], Nodeitem
      can [ :manage ], Photo
      can [ :manage ], Report
      can [ :manage ], Site
      can [ :manage ], Tag
      can [ :manage ], User
      can [ :manage ], UserProfile
      can [ :manage ], Venue
      can [ :manage ], Video
      can [ :manage ], Welcome
      can [ :manage ], Manager
      can [ :manage ], ManagerCity
      can [ :manage ], ManagerFeature
      can [ :manage ], ManagerGallery
      can [ :manage ], ManagerNewsitem
      can [ :manage ], ManagerPhoto
      can [ :manage ], ManagerReport
      can [ :manage ], ManagerSite
      can [ :manage ], ManagerTag
      can [ :manage ], ManagerUser
      can [ :manage ], ManagerVenue
    end

    #
    # if admin
    #
    can :manage, :all do
      user.group_id.to_s == "1"
    end

  end    
  user ||= User.new
  
  ###
  ### applies to all users
  ###

  can [ :index, :show ], City

  can [ :render_partial ], AuxModel
  
  can [ :new ], Event

  can [ :index, :search, :not_found, :set_show_style, :new ], Gallery
  can [ :show ], Gallery do |g|
    g.is_public && !g.is_trash
  end

  can [ :error500, :search ], Manager

  # has to be outside user auth b/c the uploading component is ajax.
  can [ :new, :create, :index, :do_upload, :not_found ], Photo
  can [ :show ], Photo do |photo|
    photo.is_public && !photo.is_trash
  end
  
  can [ :search, :not_found, :new, :index ], Report
  can [ :show ], Report do |r|
    r.is_public && !r.is_trash
  end

  can [ :new ], Review
     
  can [ :show, :newsitems, :features, :newsitems, :create_missing, :register ],  Site do |s|
    !s.is_private
  end

  can [ :index ], Tag
  can [ :show ], Tag do |t|
    true
  end

  can [ :resume, :reports, :galleries, :report, :gallery,
    :sign_in, :sign_up, :sign_out, :logout,
    :index, :show, :not_found, :github, :about ], User
  can [ :report ], User do |r|
    r.is_public && !r.is_trash
  end
  
  can [ :new, :index, :show, :not_found ], Venue

  can [ :index, :show, :view ], Video

end