Skip to content

Commit

Permalink
Merge pull request codeforamerica#34 from fullstacklabs/CS-787
Browse files Browse the repository at this point in the history
CS-787 Remove previous categories when updating BlogPost Category
  • Loading branch information
callitafeature authored Apr 4, 2019
2 parents efbb0b0 + ae4b8f2 commit 559f58d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
6 changes: 5 additions & 1 deletion app/controllers/api/v1/blog_posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ def create
end

def update
@blog_post.category_list.add(blog_post_params[:category])
if blog_post_params[:category].present?
@blog_post.categories.delete_all
@blog_post.category_list.add(blog_post_params[:category])
end
if @blog_post.update(blog_post_params)
@blog_post.reload
render json: @blog_post,
serializer: BlogPostSerializer,
status: 200
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def update
end

def destroy
resource.soft_delete
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
resource.destroy
render json: { message: 'User was deleted successfully' },
status: :destroyed
end
Expand Down
15 changes: 2 additions & 13 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,18 @@ class User < ActiveRecord::Base
:jwt_authenticatable, jwt_revocation_strategy: JWTBlacklist


# instead of deleting, indicate the user requested a delete & timestamp it
def soft_delete
update_attribute(:deleted_at, Time.current)
end

def active_for_authentication?
# Uncomment the below debug statement to view the properties of the returned self model values.
# logger.debug self.to_yaml

super && organization_approved? && !deleted_at
super && organization_approved?
end

def organization_approved?
organization.approval_status == 'approved'
end

def inactive_message
if !deleted_at && organization_approved?
super
elsif !organization_approved?
:organization_inactive
elsif deleted_at
:deleted_account
end
organization_approved? ? super : :organization_inactive
end
end
1 change: 0 additions & 1 deletion config/locales/devise.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ en:
unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your account before continuing."
organization_inactive: 'Your organization has not been approved yet.'
deleted_account: "You've deleted your account. We hope to see you again."
mailer:
confirmation_instructions:
subject: "Confirmation instructions"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveDeletedAtColumnToUsers < ActiveRecord::Migration
def change
remove_column :users, :deleted_at, :datetime
end
end
5 changes: 3 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,7 @@ CREATE TABLE public.users (
confirmation_sent_at timestamp without time zone,
unconfirmed_email character varying,
created_at timestamp without time zone,
updated_at timestamp without time zone,
deleted_at timestamp without time zone
updated_at timestamp without time zone
);


Expand Down Expand Up @@ -1935,3 +1934,5 @@ INSERT INTO schema_migrations (version) VALUES ('20190225184420');

INSERT INTO schema_migrations (version) VALUES ('20190402131619');

INSERT INTO schema_migrations (version) VALUES ('20190404161038');

0 comments on commit 559f58d

Please sign in to comment.