Sha256: 3dc0e0863b4c80fcd6ae9ff4272729ab0c1edc36c38cef6af6ea125d446ccc7f

Contents?: true

Size: 804 Bytes

Versions: 1

Compression:

Stored size: 804 Bytes

Contents

module Formol
  module Permissions
    # add methods to this module to define some rights that acts
    # differently than just checking if user has right for his profile.
    # 
    # For instance, a user can edit a post without having 'edit_post' right
    # if he wrotes it, he's able to edit it
    module SpecialRights
      # a user can edit a topic if he wrotes it
      def able_to_edit_topic?(topic)
        has_right?(:edit_topic) || (!topic.locked? && topic.user_id == user.id)
      end
      
      # a user can edit a post if he wrotes it
      def able_to_edit_post?(post)
        has_right?(:edit_post) || (!post.topic.locked? && post.user_id == user.id)
      end
      
      def able_to_create_post?(topic)
        has_right?(:create_post) && !topic.locked?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formol-0.0.4 lib/formol/generators/install/templates/lib/permissions/special_rights.rb