Giter Site home page Giter Site logo

acl2_ownership's Introduction

AclSystem2Ownership
===================

This plugin adds ownership functionality to Ezra's Zygmuntowicz acl_system plugin.
In order to use it you have to invoke 'owner' method which takes one parameter --
a string containing code that returns owner's User object. That method creates
virtual role 'owner' which you can use in your permissions strings.

Example:

class UsersController < ApplicationController
  before_filter :login_required, :only => [:update_photo]
  before_filter :find_photo   # sets @photo
  owner '@photo.user'
  access_control :update_photo => '(admin | owner)'
end

Above example gives access to users with admin role and to the owner of the
@photo object which is to be updated.

There can also be passed array of owners as owner method argument:

class UsersController < ApplicationController
  before_filter :login_required, :only => [:update_photo]
  before_filter :find_photo   # sets @photo
  owner '@users'
  access_control :update_photo => '(admin | owner)'
  
  protected
  
  def find_photo
    @photo = Photo.find(params[:id])
    @users = [@photo.owner_1, @photo.owner_2]
  end
end


page_owner
----------

There is a second virtual role added by this plugin, called 'page_owner'. It
also takes a string which returns user object as a parameter. It's sometimes
handy to have an ability to set two various users which can have access to a page
or some resources on page.
For example there are whiteboards, everybody can post new entries on them, and
authors of that entries are owners. But whiteboard belongs to one specific user
and he is the page_owner in that scenario, so:

  owner '@author', :page_owner => '@user'
  access_control :destroy => '(owner | page_owner)'

And now owner and page_owner have ability do delete whiteboard entries.


Various owners for different actions
------------------------------------

There is a possibility to define various owners for different actions:

owner '@album.user', {}, :new => '@user', :index => '@another_user', :create => '@user', :show => nil

Some actions don't have any owner, and then we can just set owners of such actions
to be nil.


TESTS
Tests won't work if acl plugin is in another directory than ../acl_system2

Author: Michal Ochman [email protected]

acl2_ownership's People

Contributors

ocher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

completelynovel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.