Skip to content

Add project and user for member #13

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -125,7 +125,9 @@ These mentioned models are tracked with the corresponding actions. Internally Ra
"id": 1,
"current_user_id": 1,
"member_id": 1,
"role_id": 1
"role_id": 1,
"project_id": 1,
"user_id": 1
}
```

19 changes: 15 additions & 4 deletions app/models/redis_notification.rb
Original file line number Diff line number Diff line change
@@ -45,10 +45,9 @@ def self.track(action, subject)
current_user_id: User&.current&.id
}

['project_id', 'issue_id', 'user_id', 'member_id', 'role_id'].each do |attribute|
if subject.has_attribute?(attribute)
attributes[:additional_data] = Hash(attributes[:additional_data]).merge({attribute.to_sym => subject.send(attribute)})
end
attributes[:additional_data] = get_additional_data(subject, attributes[:additional_data])
if attributes[:additional_data] && attributes[:additional_data].key?(:member_id)
attributes[:additional_data] = Hash(attributes[:additional_data]).merge(get_additional_data(subject.member, attributes[:additional_data]))
Comment on lines +48 to +50
Copy link
Member

Choose a reason for hiding this comment

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

Some things:

  • I find this method call a bit misleading, I'd rather call it set_additional_data.
  • I'd move this entire additional_data definition in set_additional_data method or even include the additional_data setting in this method. These are class methods, it's weird having those mixed in the private section of this class.

end

create(attributes)
@@ -68,4 +67,16 @@ def self.notification_table_exists?
def publish
RedmineRedisNotifier::Publisher.new(self).publish
end

private

def self.get_additional_data(subject, additional_data)
Copy link
Member

Choose a reason for hiding this comment

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

See my comment above regarding naming and content of this method.

["project_id", "issue_id", "user_id", "member_id", "role_id"].each do |attribute|
if subject.has_attribute?(attribute)
additional_data = Hash(additional_data).merge({attribute.to_sym => subject.send(attribute)})
end
end

additional_data
end
end
2 changes: 1 addition & 1 deletion app/views/redis_notifications/index.html.erb
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
<% when "Member" %>
<%= link_to redis_notification.subject.project.name, settings_project_path(redis_notification.subject.project, tab: "members") %>
<% when "MemberRole" %>
<%= link_to redis_notification.subject.member.user.login, user_path(redis_notification.subject.member.user) %>
<%= link_to redis_notification.subject.member.project.name, settings_project_path(redis_notification.subject.member.project, tab: "members") %>
<% when "Issue" %>
<%= link_to redis_notification.subject.subject, issue_path(redis_notification.subject) %>
<% when "User" %>