Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast forward the master branch and initial 4.1 features/fixes #259

Merged
merged 64 commits into from
Jul 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9c827ac
next release
anteriovieira Mar 11, 2017
aa39af6
feat(AuditableModelStub): implement enableTimestampAuditing() and ena…
Mar 14, 2017
4e60a5a
feat(AuditableModelStub): implemented setAuditInclude() and setAuditE…
Mar 14, 2017
80bfec5
feat(AuditableTest): test coverage increased
Mar 14, 2017
d823ff0
feat(Auditable): added more getter methods to the interface
quetzyg Mar 15, 2017
1d8885f
fix(Auditable): fixes #205 - refactor Auditable trait
quetzyg Mar 15, 2017
be3f518
chore(Auditable): rename stub class
quetzyg Mar 15, 2017
0568a36
feat(AuditableTest): refactor tests
quetzyg Mar 15, 2017
cc3b65f
fix(*): add missing new line
quetzyg Mar 15, 2017
339a0aa
fix(*): add missing new lines
quetzyg Mar 15, 2017
a0b7f7e
fix(*): code style
quetzyg Mar 15, 2017
1a45b45
Merge pull request #208 from quetzyg/fix/issue-205
anteriovieira Mar 15, 2017
a4c30e4
fix(composer): use correct branch-alias
quetzyg Mar 15, 2017
bdd45a9
Merge pull request #209 from quetzyg/4.0
quetzyg Mar 15, 2017
c4e31e5
Updated
anteriovieira Mar 17, 2017
eea672a
feat(Auditable): implement readyForAuditing() method
quetzyg Mar 18, 2017
7f6839a
feat(Auditable): update tests
quetzyg Mar 18, 2017
fc49824
fix(Auditor): fixes #212
quetzyg Mar 18, 2017
c30d211
feat(UserResolver): initial implementation
quetzyg Mar 18, 2017
345f169
fix(Auditable): fixes #213 - allow caching the config by using a User…
quetzyg Mar 18, 2017
6ae5f72
feat(Auditable): update tests
quetzyg Mar 18, 2017
186a506
Merge pull request #214 from quetzyg/4.0
quetzyg Mar 18, 2017
ee26ff0
fix(DatabaseDriver): fixes #215 - enclose variable assignment so that…
quetzyg Mar 20, 2017
9787eb6
feat(*): added CHANGELOG
quetzyg Mar 21, 2017
2dfc70c
Merge pull request #217 from quetzyg/4.0
anteriovieira Mar 21, 2017
c1e5b7e
Fix migration stub to use configurations for database driver
Mar 24, 2017
413c33b
Fix migration stub to use configurations for database driver
Mar 29, 2017
fb19e7a
Merge pull request #220 from the-great-tao/4.0
anteriovieira Mar 29, 2017
3c6ae20
fix(driver): fixes #226
quetzyg Apr 23, 2017
d89931a
Merge pull request #228 from quetzyg/fix/issue-226
quetzyg Apr 23, 2017
8faf4ff
feat(Audits): fixes #224 - log the User Agent string
quetzyg Apr 23, 2017
937dbf5
Merge pull request #229 from quetzyg/feature/user-agent
anteriovieira Apr 26, 2017
1e226f1
fix(Auditable): fixes #225 - generate a standards compliant SQL query
quetzyg Apr 30, 2017
0925042
Merge pull request #232 from quetzyg/fix/issue-225
quetzyg Apr 30, 2017
76b086b
fix(Auditable): use DISTINCT instead of GROUP BY
quetzyg Apr 30, 2017
d4d6823
fix(AuditableObserver): prevent auditing an updated event when restor…
quetzyg Apr 30, 2017
dbef64c
fix(AuditableObserver): set the attribute visibility
quetzyg Apr 30, 2017
8ea1a67
chore(AuditableObserver): wording
quetzyg Apr 30, 2017
3070c51
chore(*): updated the changelog
quetzyg Apr 30, 2017
e58253e
Merge pull request #233 from quetzyg/fix/audit-restore
quetzyg May 1, 2017
ab14f7d
fix(Auditable): remove explicit sort from the audits relation
quetzyg May 3, 2017
d6219df
Merge pull request #236 from quetzyg/fix/auditable
quetzyg May 3, 2017
440e9fa
fix(CHANGELOG): add missing entry for v4.0.5
quetzyg May 13, 2017
2e8f115
feat(Auditable): minor updates
quetzyg May 13, 2017
afca505
Fix iterating over all audits, if audible model is not resolved
mikebronner May 16, 2017
4c9b4d0
Merge pull request #244 from mikebronner/patch-1
quetzyg May 16, 2017
e250a0d
Merge remote-tracking branch 'upstream/4.0' into 4.0
quetzyg May 21, 2017
105d27e
chore(Audit): updated PHPdoc return value
quetzyg May 21, 2017
e265275
chore(CHANGELOG): version update
quetzyg May 21, 2017
6aaa175
Merge pull request #245 from quetzyg/4.0
quetzyg May 21, 2017
23e6ec2
fix(AuditableObserver): remove lingering value used in tests
quetzyg Jun 3, 2017
6c804d0
chore(AuditableObserver): wording
quetzyg Jun 3, 2017
8a62f64
feat(*): added GitHub issue template
quetzyg Jun 3, 2017
466d913
fix(*): do not export the .github directory
quetzyg Jun 3, 2017
9d063cf
feat(CHANGELOG): updated with version 4.0.7
quetzyg Jun 3, 2017
6476d55
Merge pull request #249 from quetzyg/4.0
anteriovieira Jun 4, 2017
eb5ebb3
chore(composer): updated keywords
quetzyg Jul 1, 2017
4778464
chore(Audit): remove table attribute override
quetzyg Jul 2, 2017
15c8f8c
feat(Audit): make the User relationship flexible by allowing the prim…
quetzyg Jul 2, 2017
3763c9d
feat(Audit): initial contract implementation, allowing for a more fle…
quetzyg Jul 2, 2017
cf2adc6
feat(Audit): move most of the code to a trait and implement the contract
quetzyg Jul 2, 2017
059249e
chore(*): updated branch alias
quetzyg Jul 2, 2017
0df5c98
chore(*): updated the CHANGELOG
quetzyg Jul 2, 2017
74aadaf
fix(Travis): use Trusty to allow HHVM tests again
quetzyg Jul 2, 2017
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tests export-ignore
.gitattributes export-ignore
.github export-ignore
.gitignore export-ignore
.travis.yml export-ignore
CHANGELOG.md export-ignore
phpunit.xml export-ignore
README.md export-ignore
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
| Q | A
| ----------------- | ---
| Bug? | no|yes
| New Feature? | no|yes
| Framework | Laravel|Lumen
| Framework version | 5.x.y
| Package version | 4.x.y
| PHP version | 5.x.y|7.x.y

#### Actual Behaviour

Describe the behaviour you're experiencing.


#### Expected Behaviour

Describe the behaviour you're expecting.


#### Steps to Reproduce

List all the steps needed to reproduce the issue. Make sure to include the code you're using,
any screenshots and/or other resources you find pertinent.


#### Possible Solutions

If you have any ideas on how to solve the issue, add them here.
If not, omit this part.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist: trusty

language: php

php:
Expand Down
72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## v4.1.0 (2017-07-??)
### Added
- Implemented Audit contract, enabling classes to extend other model types ([#211](https://github.com/owen-it/laravel-auditing/issues/211))

### Fixed
- Allow the User primary and foreign key to be specified in the configuration ([#251](https://github.com/owen-it/laravel-auditing/issues/251))

## v4.0.7 (2017-06-04)
### Added
- GitHub issue template file

### Fixed
- Properly fixed issue ([#233](https://github.com/owen-it/laravel-auditing/issues/233))

## v4.0.6 (2017-05-21)
### Fixed
- Calling a member function on null ([#244](https://github.com/owen-it/laravel-auditing/issues/244))

## v4.0.5 (2017-05-03)
### Fixed
- Removed problematic ORDER BY from the audits() relation method in the Auditable trait

## v4.0.4 (2017-05-01)
### Added
- Log the user agent string ([#224](https://github.com/owen-it/laravel-auditing/issues/224))

### Changed
- Updated migration stub to use the DB driver ([#220](https://github.com/owen-it/laravel-auditing/issues/220))

### Fixed
- Wrong class name for custom audit drivers ([#226](https://github.com/owen-it/laravel-auditing/issues/226))
- Use standards compliant SQL ([#225](https://github.com/owen-it/laravel-auditing/issues/225))
- Prevent creating an updated audit when restoring a model ([#233](https://github.com/owen-it/laravel-auditing/issues/233))

## v4.0.3 (2017-03-21)
### Added
- Changelog file

### Fixed
- Removal count in Database driver ([#215](https://github.com/owen-it/laravel-auditing/issues/215))

## v4.0.2 (2017-03-18)
### Added
- `OwenIt\Auditing\Contracts\UserResolver` interface
- More `Auditable` tests

### Fixed
- Non auditable events cause a `RuntimeException` to be thrown ([#212](https://github.com/owen-it/laravel-auditing/issues/212))
- `Callable` values prevent the configuration from being cached ([#213](https://github.com/owen-it/laravel-auditing/issues/213))

## v4.0.1 (2017-03-15)
### Added
- Dynamic attribute getters
- More `Auditable` tests

### Fixed
- Trait attributes can't be overridden by class implementing `Auditable` ([#205](https://github.com/owen-it/laravel-auditing/issues/205))
- Branch alias

## v4.0.0 (2017-03-11)
### Changed
- Cleaner codebase
- Better test coverage
- `Auditable` attribute mutators and casts will be honoured

### Fixed
- Only modified attributes are stored in the `Audit`
- Lumen support

### Removed
- Queue support
- `Auditable` model custom messages/fields
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<a href="https://packagist.org/packages/owen-it/laravel-auditing"><img src="https://poser.pugx.org/owen-it/laravel-auditing/v/unstable.svg" alt="Unstable Version"></a>
<a href="http://laravel.com"><img src="https://img.shields.io/badge/Laravel-5.2.x-brightgreen.svg?style=flat-square" alt="Laravel 5.2.x"></a>
<a href="http://laravel.com"><img src="https://img.shields.io/badge/Laravel-5.3.x-brightgreen.svg?style=flat-square" alt="Laravel 5.3.x"></a>
<a href="http://laravel.com"><img src="https://img.shields.io/badge/Laravel-5.4.x-brightgreen.svg?style=flat-square" alt="Laravel 5.4.x"></a>
<a href="https://packagist.org/packages/owen-it/laravel-auditing"><img src="https://poser.pugx.org/owen-it/laravel-auditing/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/owen-it/laravel-auditing"><img src="https://poser.pugx.org/owen-it/laravel-auditing/license.svg" alt="License"></a>

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "owen-it/laravel-auditing",
"description": "Audit changes of your Eloquent models in Laravel/Lumen",
"keywords": [
"activity",
"accountability",
"audit",
"auditing",
"change",
"changes",
"eloquent",
"history",
"log",
Expand All @@ -14,7 +14,8 @@
"laravel",
"lumen",
"record",
"track"
"revision",
"tracking"
],
"homepage": "https://laravel-auditing.com",
"type": "package",
Expand Down Expand Up @@ -63,7 +64,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.1-dev"
}
}
}
11 changes: 7 additions & 4 deletions config/audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

/*
|--------------------------------------------------------------------------
| User Model & Resolver
| User Keys, Model & Resolver
|--------------------------------------------------------------------------
|
| Define the User model class and how to resolve a logged User ID.
| Define the User primary and foreign keys, Eloquent model and ID resolver
| class.
|
*/

'user' => [
'model' => App\User::class,
'resolver' => function () {
'primary_key' => 'id',
'foreign_key' => 'user_id',
'model' => App\User::class,
'resolver' => function () {
return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
},
],
Expand Down
181 changes: 181 additions & 0 deletions src/Audit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php
/**
* This file is part of the Laravel Auditing package.
*
* @author Antério Vieira <[email protected]>
* @author Quetzy Garcia <[email protected]>
* @author Raphael França <[email protected]>
* @copyright 2015-2017
*
* For the full copyright and license information,
* please view the LICENSE.md file that was distributed
* with this source code.
*/

namespace OwenIt\Auditing;

use Illuminate\Support\Facades\Config;

trait Audit
{
/**
* Audit data.
*
* @var array
*/
protected $data = [];

/**
* The Audit attributes that belong to the metadata.
*
* @var array
*/
protected $metadata = [];

/**
* The Auditable attributes that were modified.
*
* @var array
*/
protected $modified = [];

/**
* {@inheritdoc}
*/
public function getConnection()
{
return static::resolveConnection(Config::get('audit.drivers.database.connection'));
}

/**
* {@inheritdoc}
*/
public function getTable()
{
return Config::get('audit.drivers.database.table', parent::getTable());
}

/**
* {@inheritdoc}
*/
public function auditable()
{
return $this->morphTo();
}

/**
* {@inheritdoc}
*/
public function user()
{
return $this->belongsTo(
Config::get('audit.user.model'),
Config::get('audit.user.foreign_key', 'user_id'),
Config::get('audit.user.primary_key', 'id')
);
}

/**
* {@inheritdoc}
*/
public function resolveData()
{
// Metadata
$this->data = [
'audit_id' => $this->id,
'audit_event' => $this->event,
'audit_url' => $this->url,
'audit_ip_address' => $this->ip_address,
'audit_user_agent' => $this->user_agent,
'audit_created_at' => $this->serializeDate($this->created_at),
'user_id' => $this->user_id,
];

if ($this->relationLoaded('user')) {
foreach ($this->user->attributesToArray() as $attribute => $value) {
$this->data['user_'.$attribute] = $value;
}
}

$this->metadata = array_keys($this->data);

// Modified Auditable attributes
foreach ($this->new_values as $key => $value) {
$this->data['new_'.$key] = $value;
}

foreach ($this->old_values as $key => $value) {
$this->data['old_'.$key] = $value;
}

$this->modified = array_diff_key(array_keys($this->data), $this->metadata);

return $this->data;
}

/**
* {@inheritdoc}
*/
public function getDataValue($key)
{
if (!array_key_exists($key, $this->data)) {
return;
}

$value = $this->data[$key];

// Apply a mutator or a cast the Auditable model may have defined
if ($this->auditable && starts_with($key, ['new_', 'old_'])) {
$originalKey = substr($key, 4);

if ($this->auditable->hasGetMutator($originalKey)) {
return $this->auditable->mutateAttribute($originalKey, $value);
}

if ($this->auditable->hasCast($originalKey)) {
return $this->auditable->castAttribute($originalKey, $value);
}
}

return $value;
}

/**
* {@inheritdoc}
*/
public function getMetadata($json = false, $options = 0, $depth = 512)
{
if (empty($this->data)) {
$this->resolveData();
}

$metadata = [];

foreach ($this->metadata as $key) {
$metadata[$key] = $this->getDataValue($key);
}

return $json ? json_encode($metadata, $options, $depth) : $metadata;
}

/**
* {@inheritdoc}
*/
public function getModified($json = false, $options = 0, $depth = 512)
{
if (empty($this->data)) {
$this->resolveData();
}

$modified = [];

foreach ($this->modified as $key) {
$attribute = substr($key, 4);
$state = substr($key, 0, 3);

$modified[$attribute][$state] = $this->getDataValue($key);
}

return $json ? json_encode($modified, $options, $depth) : $modified;
}
}
Loading