Created
September 17, 2012 23:35
-
-
Save nfriend21/3740431 to your computer and use it in GitHub Desktop.
cancan ability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
user ||= User.new #guest user | |
can :manage, :all if user.role == "owner" | |
if user.role == "employee" | |
can :read, Company | |
can :create, Project | |
can :read, [Project] do |project| | |
project.tasks.try(:user_id) == user.id | |
end | |
can :manage, Project do |project| | |
project.try(:owner_id) == user.id | |
end | |
can :create, Task | |
can :manage, Task do |task| | |
task.try(:user_id) == user.id | |
end | |
end | |
if user.role == nil | |
can :manage, :all | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row" style="border-bottom: 1px solid #9d9d9d; padding-bottom: 10px;"> | |
<aside class="span9 co_header_bar" style="margin-left: -3px;"> | |
<h1> | |
<%= @company.name %> | |
<%= link_to "+ Project", new_company_project_path(@company), class: "btn btn-medium btn-primary" %> | |
</h1> | |
</aside> | |
<% if can? :manage, @company %> | |
<aside class="span2 co_header_bar_links pull-right"> | |
<%= link_to ' ', [:edit, @company], :class => 'icon-pencil' %> | |
</aside> | |
<% end %> | |
</div> | |
<br> | |
<% @projects.each do |c| %> | |
<% if can? :manage, c %> | |
<div class="row"> | |
<aside class="span9 co_header_bar"> | |
<%= c.name %> | |
<%= link_to "+ Task", new_company_project_task_path(@company, c), class: "btn btn-medium btn-primary" %> <!--span class="sub_text_list"><%#= pluralize(c.tasks.count, "task") %></span--> | |
</aside> | |
<aside class="span2 co_header_bar_links pull-right"> | |
<%= link_to ' ', [@company, c], :class => 'icon-eye-open' %> | |
<%= link_to ' ', [:edit, @company, c], :class => 'icon-pencil' %> | |
<%= link_to ' ', [@company, c], method: :delete , data: { confirm: "Are you sure?" }, :class => 'icon-trash' %> | |
</aside> | |
</div> | |
<% end %> | |
<% c.tasks.each do |t| %> | |
<% if can? :manage, t %> | |
<div class ="row task_list"> | |
<li> | |
<aside class="span9"> | |
<section> | |
<%= t.content %><span class="sub_text_list"> <%= t.user.name %>, Due: <%= t.due_date %></span> | |
</section> | |
</aside> | |
<aside class="span2 pull-right"> | |
<section> | |
<%= link_to 'View', [@company, c, t], :class => 'btn btn-mini' %> | |
<%= link_to 'Edit', [:edit, @company, c, t], :class => 'btn btn-mini' %> | |
<%= link_to "Delete", [@company, c, t], method: :delete , data: { confirm: "Are you sure?" }, :class => 'btn btn-mini btn-danger' %> | |
</section> | |
</aside> | |
</li> | |
</div> | |
<% end %> | |
<% end %> | |
<br> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment