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

Fix audit log error when custom emoji is copied from remote server #11876

Merged

Conversation

highemerly
Copy link
Contributor

Expected behaviour

When I copy custom emojis from remote server,

  • Custom emoji can be copied.
  • This action is recorded to audit logs.

Actual behaviour

When I copy custom emojis from remote server,

  • Custom emoji can be copied.
  • This action is NOT recorded to audit logs.

Steps to reproduce the problem

In admin/custom_emojis pages, check some custom emoji and click "copy" button.

Specifications

master branch

copied_custom_emoji = custom_emoji.copy!
log_action :create, copied_custom_emoji
custom_emoji.copy!
log_action :create, custom_emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check why output of custom_emoji.copy! doesn't work, but this would be wrong, since it will log the creation of the remote emoji, and not the local one...

Copy link
Contributor Author

@highemerly highemerly Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your concern. It seems that the output of custom_emoji.copy! is just true/false. Following changes are acceptable for you? I'll send pull request later.

diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb
index edb1bec..0dacaf6 100644
--- a/app/models/custom_emoji.rb
+++ b/app/models/custom_emoji.rb
@@ -63,7 +63,7 @@ class CustomEmoji < ApplicationRecord
   def copy!
     copy = self.class.find_or_initialize_by(domain: nil, shortcode: shortcode)
     copy.image = image
-    copy.save!
+    copy.tap(&:save!)
   end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that is a good fix! I've run into that mistake a few times before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sent new fix.

@highemerly highemerly force-pushed the fix-log-action-when-copy-customemoji branch from bfec420 to 725115a Compare September 17, 2019 15:40
@Gargron Gargron merged commit 3919571 into mastodon:master Sep 17, 2019
hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants