Giter VIP home page Giter VIP logo

footprint's Introduction

Footprint

Build Status Coverage Total Downloads License

This plugin allows you to pass the currently logged in user to the model layer of a CakePHP 3 application.

It comes bundled with the FootprintBehavior to allow you control over columns such as user_id, created_by, company_id just like the core's TimestampBehavior.

Install

Using Composer:

composer require muffin/footprint:dev-master

You then need to load the plugin. In boostrap.php, something like:

\Cake\Core\Plugin::load('Muffin/Footprint');

Usage

Trait

First, you will need to include the Muffin\Footprint\Auth\FootprintAwareTrait to your AppController:

use Muffin\Footprint\Auth\FootprintAwareTrait;

class AppController extends Controller
{
    use FootprintAwareTrait;
}

This will attach the Muffin\Footprint\Event\FootprintListener to models which will inject the currently logged in user's instance on Model.beforeSave and Model.afterSave in the _footprint key of $options.

The user record provided by AuthComponent is converted to User entity before passing to models. If your AuthComponent is configured to use a non-default users table you must set the $_userModel property of the trait to same table:

public function beforeFilter(\Cake\Event\Event $event)
{
	$this->_userModel = 'Members';
}

Behavior

To use the included behavior to automatically update the created_by and updated_by fields of a record for example, add the following to your table's initialize() method:

$this->addBehavior('Muffin/Footprint.Footprint');

You can customize that like so:

$this->addBehavior('Footprint', [
    'events' => [
        'Model.beforeSave' => [
        	'user_id' => 'new',
            'company_id' => 'new',
            'modified_by' => 'always'
        ]
    ],
    'propertiesMap' => [
        'company_id' => '_footprint.company.id',
    ],
]);

This will insert the currently logged in user's primary key in user_id and modified_by fields when creating a record, on the modified_by field again when updating the record and it will use the associated user record's company id in the company_id field when creating a record.

Patches & Features

  • Fork
  • Mod, fix
  • Test - this is important, so it's not unintentionally broken
  • Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
  • Pull request - bonus point for topic branches

Bugs & Feedback

http://github.com/usemuffin/footprint/issues

Credits

This was originally inspired by Ceeram/Blame.

License

Copyright (c) 2015, Use Muffin and licensed under The MIT License.

footprint's People

Contributors

admad avatar jadb avatar lorenzo avatar modpluz avatar dakota avatar

Watchers

James Cloos avatar  avatar

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.