简体   繁体   中英

Approval of edits

I want to know the best solution for reviewing edits of a user that needs to be approved by a admin.

At the moment i have a Users table with the following fields.

  • Username
  • Password
  • Created_at
  • Updated_at

I have a relation table user_profile with the following fields

  • User_id
  • Firstname
  • Lastname
  • Street
  • Zip
  • State
  • About_me

I also have a table pending_user_profile for the approvals

  • User_id
  • Firstname
  • Lastname
  • Street
  • Zip
  • State
  • About_me

At the moment i am checking if there is a user_id in the pending_user_profile table to show the pending data inside the edit screen on the application.

Im checking it like this: PendingUser::where('user_id', $this->id)->exists();

The pending data is also shown for the admin. (basically im just getting everything inside the pending_user_profile. So the admin knows what users have edited there information.

Im getting the data like this: PendingUser::all();

First question: I'm not sure how this will hold up when i have loads of users. So im trying to find a better solution for this, or want to know that the solution im using now is maybe totally fine and i should not be worried about it at all. Is my approach for checking for pending fields a good approach?

Second question: When storing the pending fields im not sure how to deal with it. Should i compare all fields before submitting them to the pending fields? this way im just storing the fields that are changed. The downside for this option is that i have to get data from 2 separate tables.

Any help will be appreciated.

Thanks in advance!

I wouldn't create another table for this. Just add a version and a status to your user_profile table. If the user edit it, create a new record, with a higher version, with a status pending . You can compare then. If the admin accepts it, set the status to active and delete or keep the previous one.

Then you can set relationships for both for the User:

public function pendingProfile() {
    return $this->hasOne('UserProfile')
        ->where('status', 'pending')
        ->orderBy('version', 'desc');
}

public function currentProfile() {
    return $this->hasOne('UserProfile')->where('status', 'active');

    // Here you can also take the latest version if you delete any other active, 
    // or add the where and order as above to get the latest
}

If you don't mind adding a new table:

  1. you could store the new values to the extra table and in the main table you could add a column which specifies whether the row has a pending edit. When admin approves the changes, the new values are fetched from the extra table and updated into the main table.
  2. You can immediately update the main table but keep old data in the extra table. This way if the admin approves, you simply delete old data and if rejected, the old data is returned. Remember to update the status column

i suggest the DB structure i have found and asked a question about in this link : in this link

i get a pretty good feed back on this system with saving multiple table changes which every table have their on diffrent structure. and also i should tell that i am using Zend Frameword.so for users that their changes need admin approval i do not use for example Product model .i uses another mother named ChangeApprovalNeededProduct model that extends Product Model but when calling save method on them i prevent system from saving changes to Product table instead i gather changed data in an key value table and save them somewhere else named Changes table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM