Skip to content

Commit

Permalink
Added public concerto check to ability.rb, closing #83
Browse files Browse the repository at this point in the history
  • Loading branch information
augustf committed May 3, 2012
1 parent 454a683 commit 3101044
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,49 @@ def initialize(accessor)
# Anything real can read a user
can :read, User if accessor.persisted?

## Feeds
# Anything can read a viewable feed
# the ability to 'read' a feed implies that
# you can browse it's contents as well
can :read, Feed, :is_viewable => true

## Content
# Content approved on public feeds is publcally accessible.
can :read, Content, :submissions => {:feed => {:is_viewable => true}, :moderation_flag => true}
# If any of the submissions can be read the content can be read too.
can :read, Content do |content|
content.submissions.any?{|s| can?(:read, s)}
end

## Fields
# Anything can read fields and positions.
# Only admin users can edit them.
can :read, Field

## Positions
can :read, Position

## Membership
# Group leaders are public, anyone can view them.
can :read, Membership, :level => Membership::LEVELS[:leader]

## Groups
# Groups are only public if something they manage is viewable.
can :read, Group do |group|
group.feeds.where(:is_submittable => true).exists? || group.feeds.where(:is_viewable => true).exists?
end
can :read, Group do |group|
group.screens.where(:is_public => true).exists?
#Only define these permissive settings if concerto is set to be public
if ConcertoConfig[:public_concerto] == "true"
## Feeds
# Anything can read a viewable feed
# the ability to 'read' a feed implies that
# you can browse it's contents as well
can :read, Feed, :is_viewable => true

## Content
# Content approved on public feeds is publcally accessible.
can :read, Content, :submissions => {:feed => {:is_viewable => true}, :moderation_flag => true}
# If any of the submissions can be read the content can be read too.
can :read, Content do |content|
content.submissions.any?{|s| can?(:read, s)}
end

## Fields
# Anything can read fields and positions.
# Only admin users can edit them.
can :read, Field

## Positions
can :read, Position

## Membership
# Group leaders are public, anyone can view them.
can :read, Membership, :level => Membership::LEVELS[:leader]

## Groups
# Groups are only public if something they manage is viewable.
can :read, Group do |group|
group.feeds.where(:is_submittable => true).exists? || group.feeds.where(:is_viewable => true).exists?
end
can :read, Group do |group|
group.screens.where(:is_public => true).exists?
end

## Templates
# Oddly enough, templates store a hidden flag instead of public
# like everything else.
can :read, Template, :is_hidden => false
end

## Templates
# Oddly enough, templates store a hidden flag instead of public
# like everything else.
can :read, Template, :is_hidden => false


# Load abilities based on the type of object.
# We should do this at the bottom to make sure to
# override any generic attributes we assigned above.
Expand Down

0 comments on commit 3101044

Please sign in to comment.