Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e9a53d4
Update for Cake 4.
ADmad Aug 8, 2019
af0d259
Fix CS errors.
ADmad Aug 8, 2019
625dd9b
Update travis config
ADmad Aug 8, 2019
647f67d
Fix type hints.
ADmad Aug 8, 2019
48b065a
fixed typo
mrothauer Sep 12, 2019
cc418f7
Fix for Stable Cake Release
JacobAGTyler Dec 30, 2019
4a23f72
Update Coding Standards Check
JacobAGTyler Dec 30, 2019
1b054ed
Revert to ^4.0 not ^4.0.1
JacobAGTyler Jan 20, 2020
9eee1c5
Merge pull request #64 from JacobAGTyler/cake-4.x
ADmad Jan 20, 2020
5243863
Merge branch 'master' into cake-4.x
ADmad Jan 20, 2020
202bf82
Fix types
ADmad Jan 20, 2020
158ce18
Run static analysis check
ADmad Jan 20, 2020
4a94305
update phpunit constraint
ADmad Jan 20, 2020
26d3cd6
Update readme
ADmad Jan 20, 2020
628c13b
Fix travis config
ADmad Jan 20, 2020
dd0e45f
Add support for authentication plugin
ADmad Jan 20, 2020
57b2d3e
Fix coverage job
ADmad Jan 20, 2020
ffa0c78
Updating readme
challgren Feb 1, 2020
4bf3365
Merge pull request #66 from challgren/patch-1
ADmad Feb 1, 2020
866ba89
Call the correct interface method
dakota Aug 19, 2020
74383ea
Merge pull request #68 from dakota/patch-1
ADmad Aug 19, 2020
0931dd0
Fix CS errors
ADmad Aug 19, 2020
67e043f
Merge branch 'master' into cake-4.x
ADmad Aug 19, 2020
82b6bac
Cleanup whitespace
ADmad Aug 19, 2020
bf2391b
Add Plugin Manifest (#69)
JacobAGTyler Aug 20, 2020
3564b14
Update readme
ADmad Aug 20, 2020
075e6f4
Improve identity info extraction.
ADmad Aug 20, 2020
8125598
Update travis config
ADmad Aug 20, 2020
1c196ff
Fix property visibility
ADmad Aug 20, 2020
5c6a9b0
Update use of deprecated TableRegistry
ADmad Aug 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/composer.lock
/plugins
/vendor
.phpunit.result.cache
.idea
25 changes: 14 additions & 11 deletions 25 .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
language: php

dist: trusty

php:
- 5.6
- 7.2
- 7.3
- 7.4

env:
Expand All @@ -16,25 +12,32 @@ matrix:
fast_finish: true

include:
- php: 7.1
- php: 7.2
env: PHPCS=1 DEFAULT=0

- php: 5.6
- php: 7.2
env: STATIC_ANALYSIS=1 DEFAULT=0

- php: 7.2
env: PREFER_LOWEST=1

before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi

- if [[ $PREFER_LOWEST != 1 ]]; then composer install --no-interaction; fi
- if [[ $PREFER_LOWEST = 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi

- if [[ $STATIC_ANALYSIS == 1 ]]; then composer require --dev phpstan/phpstan:^0.12; fi

script:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT == 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi

- if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
- if [[ $STATIC_ANALYSIS == 1 ]]; then vendor/bin/phpstan analyse src; fi

after_success:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION == 7.2 ]]; then bash <(curl -s https://codecov.io/bash); fi

notifications:
email: false
84 changes: 21 additions & 63 deletions 84 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,57 @@
[![Total Downloads](https://img.shields.io/packagist/dt/muffin/footprint.svg?style=flat-square)](https://packagist.org/packages/muffin/footprint)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)

This plugin allows you to pass the currently logged in user to the model layer of a CakePHP 3
application.
This plugin allows you to pass the currently logged in user info to the model layer
of a CakePHP 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`.
It comes bundled with the `FootprintBehavior` to allow you control over columns
such as `user_id`, `created_by`, `company_id` similar to the core's `TimestampBehavior`.

## Install

Using [Composer][composer]:

```
composer require muffin/footprint

```

You then need to load the plugin by running console command:

```bash
bin/cake plugin load Muffin/Footprint
bin/cake plugin load Muffin/Footprint
```

## Usage

### Trait

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

```php
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.beforeFind` 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:

```php
public function initialize()
{
parent::initialize();

// Specify the user model if required. Defaults to "Users".
$this->_userModel = 'YourPlugin.Members';

$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'userModel' => $this->_userModel, // Use same model for AuthComponent
],
],
]);
}
```

#### Using Footprint with cakephp/authentication

If you are using the `cakephp/authentication` plugin instead of the `AuthComponent`, you will need to update your controller to tell Footprint where to find the identity. To do so, update the trait declaration and overwride `_setCurrentUser` to get the identity from the request:

```php
use Muffin\Footprint\Auth\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.beforeFind` in the `_footprint` key of `$options`.

class AppController extends Controller
{
use FootprintAwareTrait {
_setCurrentUser as _footprintSetCurrentUser;
}

protected function _setCurrentUser($user = null)
{
if (!$user) {
$user = $this->request->getAttribute('identity')->getOriginalData();
}

return $this->_footprintSetCurrentUser($user);
}
}
```
Your controller needs to have either `cakephp/authentication` plugin's `AuthenticationComponent`
or CakePHP core's deprecated `AuthComponent` loaded so that the user identity
can be fetched.

### Behavior

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

```php
$this->addBehavior('Muffin/Footprint.Footprint');
Expand All @@ -117,9 +78,10 @@ $this->addBehavior('Muffin/Footprint.Footprint', [
]);
```

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.
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.

## Warning

Expand All @@ -136,18 +98,14 @@ is attached after `Controller::initialize()` is run.
* 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)
* 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-Present, [Use Muffin][muffin] and licensed under [The MIT License][mit].
Expand Down
12 changes: 8 additions & 4 deletions 12 composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muffin/footprint",
"description": "CakePHP 3.0+ plugin to allow passing currently logged in user to model layer",
"description": "CakePHP plugin to allow passing currently logged in user to model layer",
"type": "cakephp-plugin",
"keywords": [
"cakephp",
Expand Down Expand Up @@ -30,11 +30,15 @@
"source": "https://github.com/usemuffin/footprint"
},
"require": {
"cakephp/cakephp": "^3.5"
"cakephp/cakephp": "^4.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "^5.7.14|^6.0"
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "~8.5.0"
},
"scripts": {
"cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions 10 phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
level: 6
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
ignoreErrors:
-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
path: src/Model/Behavior/FootprintBehavior.php
11 changes: 3 additions & 8 deletions 11 phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@
</listener>
</listeners>

<!-- Prevent coverage reports from looking in tests and vendors -->
<filter>
<blacklist>
<directory suffix=".php">./vendor/</directory>
<directory suffix=".ctp">./vendor/</directory>

<directory suffix=".php">./tests/</directory>
<directory suffix=".ctp">./tests/</directory>
</blacklist>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.