Code Monkey home page Code Monkey logo

approval's People

Contributors

cjmellor avatar dependabot[bot] avatar gerb-ster avatar github-actions[bot] avatar laravel-shift avatar mtawil avatar nunodonato avatar rawilk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

approval's Issues

WithoutApproval not working on create model

# 1
\App\Models\Process::withoutApproval()->create('name'  =>  'xyz', 'description' => 'abc') // Method cannot be called statically.

# 2
$process = new \App\Models\Process();

$process->withoutApproval()->create([ 'name'  =>  'xyz', 'description' => 'abc']);

This creates an approval record with a pending status instead of directly writing to the processes table.

Issue when rolling back models that contain json fields

This is done in Laravel 10

Let's say I've got the following Model:

class Post extends Model
{
use MustBeApproved;

protected $fillable = [
    "config",
];

protected $casts = [
    "config" => "json",
];
}

Now let's assume we're making different API calls where we change this Model and approve the modifications, the creation works fine

$post = new Post();
$post->config = ['checked' => false];
$post->save();

When updating the post (which needs an approval)

$post = Post::find([id]);
$post->config = ['checked' => true];
$post->save();

I get the following approvals, which I already approved in this image, but you can already see the discrepancy in data
post_approved

after rolling back this change I get the following approvals
post_rolled_back

Now after approving the rolled-back approval (which is pending as well) I get the error
"message": "json_decode(): Argument https://github.com/cjmellor/approval/pull/1 ($json) must be of type string, array given", "exception": "TypeError", "file": "/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Casts/Json.php"

Problem with ide-helper generator

I am talking about this https://github.com/barryvdh/laravel-ide-helper. A must use package if you develop with vscode.
If you run

php artisan ide-helper:generate -q

You will get

Exception: Target class [approval] does not exist.
Skipping \Cjmellor\Approval\Facades\Approval.
Exception: Target class [approval] does not exist.
Skipping \Cjmellor\Approval\Facades\Approval.

approvalable_id not save

I have created a new record, but the record approvalable_id is not saved. Is there any problem?

image

approvalModelExists() MySQL bug

In your approvalModelExists method, you are checking for an exact match for new_data and original_data via json_encode. I'm not sure how .sqlite formats data in json columns, but it appears to be the same as json_encode, since it works for your tests. In my local database I'm running MySQL 8, and it puts spaces between the key and value pairs in those columns, so the exact match in your query isn't working because of slight formatting differences between php and mysql, and thus duplicates will always be created.

I've tried the following and it seems to work:

return Approval::where('state', ApprovalStatus::Pending)
    ->whereJsonContains('new_data', $model->getDirty())
    ->whereJsonContains('original_data', $model->getOriginalMatchingChanges())
    ->exists();

If you want, I can submit a PR using the whereJsonContains query builder method.

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.