Class: Ability

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

Instance Method Summary (collapse)

Constructor Details

- (Ability) initialize(user)

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
# File 'app/models/ability.rb', line 4

def initialize(user)

  if (user.present?)
    case user.role.to_sym

      when :admin
        can :create, Project
        can :read, Project, :id => user.project_ids
        can [:update, :destroy], Project do |project|
          (user.project_ids.include? project.id) && (user.project_owner? project.id) ? true : false
        end

        can :create, Prototype
        can :read, Prototype, :project_id => user.project_ids
        can :update, Prototype, :project_id => user.project_ids, :editable => true

        can :create, Mockup
        can :read, Mockup, :project_id => user.project_ids
        can [:update, :destroy], Mockup, :project_id => user.project_ids, :editable => true

        can :create, Test
        can [:read, :update], Test, :project_id => user.project_ids
        can :show_through_digest, Test

        can :create, Task
        can :read, Task, :project_id => user.project_ids
        can :update, Task, :project_id => user.project_ids, :editable => true
        can :destroy, Task do |task|
          (user.project_ids.include? task.project_id) && (user.project_owner? task.project_id) ? true : false
        end

        can :create, Image
        can [:read, :destroy], Image, :project_id => user.project_ids

        can :create, Record
        can :update, Record
        can :read, Record


        can :create, TaskRun
        can :update, TaskRun, :user_id => user.id

        can :create, TestRun
        can :update, TestRun, :user_id => user.id

        can :read, Result, :project_id => user.project_ids

      when :tester
        can :create, Record

        can :show_through_digest, Test

        can :create, TaskRun
        can :update, TaskRun, :user_id => user.id

        can :create, TestRun
        can :update, TestRun, :user_id => user.id
    end
  else
    can :show_through_digest, Test, access: 'free'
  end
  # Define abilities for the passed in user here. For example:
  #
  #   user ||= User.new # guest user (not logged in)
  #   if user.admin?
  #     can :manage, :all
  #   else
  #     can :read, :all
  #   end
  #
  # The first argument to `can` is the action you are giving the user
  # permission to do.
  # If you pass :manage it will apply to every action. Other common actions
  # here are :read, :create, :update and :destroy.
  #
  # The second argument is the resource the user can perform the action on.
  # If you pass :all it will apply to every resource. Otherwise pass a Ruby
  # class of the resource.
  #
  # The third argument is an optional hash of conditions to further filter the
  # objects.
  # For example, here the user can only update published articles.
  #
  #   can :update, Article, :published => true
  #
  # See the wiki for details:
  # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
end