-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add soft delete to lsg bodies. #101
base: main
Are you sure you want to change the base?
Conversation
def archive | ||
id = params[:lsg_body_id] | ||
@lsg_body = LsgBody.find(id) | ||
@lsg_body.archive! | ||
redirect_to lsg_bodies_path | ||
end | ||
|
||
def unarchive | ||
id = params[:lsg_body_id] | ||
@lsg_body = LsgBody.find(id) | ||
@lsg_body.unarchive! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These endpoints should have an authorized check.
Use pundit for writing policies for auth check
https://github.com/varvet/pundit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have rewritten the policy in lsg_bodies_policy. Needs review.
app/models/lsg_body.rb
Outdated
def archive! | ||
update(archived: true) | ||
end | ||
|
||
def unarchive! | ||
update(archived: false) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be in the controller itself as we aren't using this method anywhere else. It's good to add a scope instead that will list live LSG's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Moved to the controller. Have added a scope to list live lsgs.
db/schema.rb
Outdated
@@ -79,6 +79,8 @@ | |||
t.datetime "updated_at", precision: 6, null: false | |||
t.string "code" | |||
t.uuid "district_id", null: false | |||
t.boolean "archive", default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a typo. Rollback the current migration and drop archive
field from lsg_body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -0,0 +1,5 @@ | |||
class AddArchivedToLsgBodies < ActiveRecord::Migration[6.1] | |||
def change | |||
add_column :lsg_bodies, :archived, :boolean, default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add a filed archived_at
so that we could figure out when the record was archived?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep record of all archive actions when was archived and when was unarchived like we have logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll then have :archived, :archived_at fields. Won't it be ideal to keep only one of these? Both the fields can serve as a flag. So should we only go with the :archived_at field?
f260952
to
9de96c5
Compare
9de96c5
to
ba26323
Compare
Proposed Changes
closes #100