Feature #42630 » Add-reaction-feature.patch
| app/assets/images/icons.svg | ||
|---|---|---|
| 459 | 459 |
<path d="M19 15v6h3"/> |
| 460 | 460 |
<path d="M11 21v-6l2.5 3l2.5 -3v6"/> |
| 461 | 461 |
</symbol> |
| 462 |
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--thumb-up"> |
|
| 463 |
<path d="M7 11v8a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1v-7a1 1 0 0 1 1 -1h3a4 4 0 0 0 4 -4v-1a2 2 0 0 1 4 0v5h3a2 2 0 0 1 2 2l-1 5a2 3 0 0 1 -2 2h-7a3 3 0 0 1 -3 -3"/> |
|
| 464 |
</symbol> |
|
| 465 |
<symbol viewBox="0 0 24 24" id="icon--thumb-up-filled"> |
|
| 466 |
<path d="M13 3a3 3 0 0 1 2.995 2.824l.005 .176v4h2a3 3 0 0 1 2.98 2.65l.015 .174l.005 .176l-.02 .196l-1.006 5.032c-.381 1.626 -1.502 2.796 -2.81 2.78l-.164 -.008h-8a1 1 0 0 1 -.993 -.883l-.007 -.117l.001 -9.536a1 1 0 0 1 .5 -.865a2.998 2.998 0 0 0 1.492 -2.397l.007 -.202v-1a3 3 0 0 1 3 -3z"/> |
|
| 467 |
<path d="M5 10a1 1 0 0 1 .993 .883l.007 .117v9a1 1 0 0 1 -.883 .993l-.117 .007h-1a2 2 0 0 1 -1.995 -1.85l-.005 -.15v-7a2 2 0 0 1 1.85 -1.995l.15 -.005h1z"/> |
|
| 468 |
</symbol> |
|
| 462 | 469 |
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--time"> |
| 463 | 470 |
<path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0"/> |
| 464 | 471 |
<path d="M12 7v5l3 3"/> |
| app/assets/javascripts/application-legacy.js | ||
|---|---|---|
| 1222 | 1222 |
}); |
| 1223 | 1223 |
} |
| 1224 | 1224 | |
| 1225 |
function setupHoverTooltips() {
|
|
| 1226 |
$("[title]:not(.no-tooltip)").tooltip({
|
|
| 1225 |
function setupHoverTooltips(container) {
|
|
| 1226 |
$(container || 'body').find("[title]:not(.no-tooltip)").tooltip({
|
|
| 1227 | 1227 |
show: {
|
| 1228 | 1228 |
delay: 400 |
| 1229 | 1229 |
}, |
| ... | ... | |
| 1233 | 1233 |
} |
| 1234 | 1234 |
}); |
| 1235 | 1235 |
} |
| 1236 | ||
| 1236 |
function removeHoverTooltips(container) {
|
|
| 1237 |
$(container || 'body').find("[title]:not(.no-tooltip)").tooltip('destroy')
|
|
| 1238 |
} |
|
| 1237 | 1239 |
$(function() { setupHoverTooltips(); });
|
| 1238 | 1240 | |
| 1239 | 1241 |
function inlineAutoComplete(element) {
|
| app/assets/stylesheets/application.css | ||
|---|---|---|
| 2052 | 2052 | |
| 2053 | 2053 |
img.filecontent.image {background-image: url(/transparent.png);}
|
| 2054 | 2054 | |
| 2055 |
/* Reaction styles */ |
|
| 2056 |
.reaction-button.reacted .icon-svg {
|
|
| 2057 |
fill: #126fa7; |
|
| 2058 |
stroke: none; |
|
| 2059 |
} |
|
| 2060 |
.reaction-button.reacted:hover .icon-svg {
|
|
| 2061 |
fill: #c61a1a; |
|
| 2062 |
} |
|
| 2063 |
.reaction-button .icon-label {
|
|
| 2064 |
margin-left: 3px; |
|
| 2065 |
margin-bottom: -1px; |
|
| 2066 |
} |
|
| 2067 |
div.issue.details .reaction {
|
|
| 2068 |
float: right; |
|
| 2069 |
font-size: 0.9em; |
|
| 2070 |
margin-top: 0.5em; |
|
| 2071 |
} |
|
| 2072 |
div.message .reaction {
|
|
| 2073 |
float: right; |
|
| 2074 |
font-size: 0.9em; |
|
| 2075 |
} |
|
| 2076 |
div.news .reaction {
|
|
| 2077 |
float: right; |
|
| 2078 |
font-size: 0.9em; |
|
| 2079 |
} |
|
| 2080 | ||
| 2055 | 2081 |
/* Custom JQuery styles */ |
| 2056 | 2082 |
.ui-autocomplete, .ui-menu {
|
| 2057 | 2083 |
border-radius: 2px; |
| app/controllers/messages_controller.rb | ||
|---|---|---|
| 49 | 49 |
reorder("#{Message.table_name}.created_on ASC, #{Message.table_name}.id ASC").
|
| 50 | 50 |
limit(@reply_pages.per_page). |
| 51 | 51 |
offset(@reply_pages.offset). |
| 52 |
to_a
|
|
| 52 |
load_with_reactions
|
|
| 53 | 53 | |
| 54 | 54 |
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
| 55 | 55 |
render :action => "show", :layout => false if request.xhr? |
| app/controllers/news_controller.rb | ||
|---|---|---|
| 67 | 67 |
end |
| 68 | 68 | |
| 69 | 69 |
def show |
| 70 |
@comments = @news.comments.to_a
|
|
| 70 |
@comments = @news.comments.load_with_reactions
|
|
| 71 | 71 |
@comments.reverse! if User.current.wants_comments_in_reverse_order? |
| 72 | 72 |
end |
| 73 | 73 | |
| app/controllers/reactions_controller.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
class ReactionsController < ApplicationController |
|
| 21 |
before_action :check_enabled |
|
| 22 | ||
| 23 |
before_action :require_login |
|
| 24 |
before_action :set_object, :authorize_reactable |
|
| 25 | ||
| 26 |
def create |
|
| 27 |
@reaction = @object.reactions.find_or_create_by!(user: User.current) |
|
| 28 |
end |
|
| 29 | ||
| 30 |
def destroy |
|
| 31 |
@reaction = @object.reactions.by(User.current).find_by(id: params[:id]) |
|
| 32 |
@reaction&.destroy |
|
| 33 |
end |
|
| 34 | ||
| 35 |
private |
|
| 36 | ||
| 37 |
def check_enabled |
|
| 38 |
render_403 unless Setting.reactions_enabled? |
|
| 39 |
end |
|
| 40 | ||
| 41 |
def set_object |
|
| 42 |
object_type = params[:object_type] |
|
| 43 | ||
| 44 |
unless Redmine::Reaction::REACTABLE_TYPES.include?(object_type) |
|
| 45 |
render_403 |
|
| 46 |
return |
|
| 47 |
end |
|
| 48 | ||
| 49 |
@object = object_type.constantize.find(params[:object_id]) |
|
| 50 |
end |
|
| 51 | ||
| 52 |
def authorize_reactable |
|
| 53 |
render_403 unless @object.visible?(User.current) |
|
| 54 |
end |
|
| 55 |
end |
|
| app/helpers/issues_helper.rb | ||
|---|---|---|
| 22 | 22 |
include Redmine::Export::PDF::IssuesPdfHelper |
| 23 | 23 |
include IssueStatusesHelper |
| 24 | 24 |
include QueriesHelper |
| 25 |
include ReactionsHelper |
|
| 25 | 26 | |
| 26 | 27 |
def issue_list(issues, &) |
| 27 | 28 |
ancestors = [] |
| app/helpers/journals_helper.rb | ||
|---|---|---|
| 19 | 19 | |
| 20 | 20 |
module JournalsHelper |
| 21 | 21 |
include Redmine::QuoteReply::Helper |
| 22 |
include ReactionsHelper |
|
| 22 | 23 | |
| 23 | 24 |
# Returns the attachments of a journal that are displayed as thumbnails |
| 24 | 25 |
def journal_thumbnail_attachments(journal) |
| ... | ... | |
| 41 | 42 |
end |
| 42 | 43 | |
| 43 | 44 |
if journal.notes.present? |
| 45 |
links << reaction_button(journal) |
|
| 46 | ||
| 44 | 47 |
if options[:reply_links] |
| 45 | 48 |
url = quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice) |
| 46 | 49 |
links << quote_reply(url, "#journal-#{journal.id}-notes", icon_only: true)
|
| app/helpers/messages_helper.rb | ||
|---|---|---|
| 19 | 19 | |
| 20 | 20 |
module MessagesHelper |
| 21 | 21 |
include Redmine::QuoteReply::Helper |
| 22 |
include ReactionsHelper |
|
| 22 | 23 |
end |
| app/helpers/news_helper.rb | ||
|---|---|---|
| 18 | 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | 19 | |
| 20 | 20 |
module NewsHelper |
| 21 |
include ReactionsHelper |
|
| 21 | 22 |
end |
| app/helpers/reactions_helper.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
module ReactionsHelper |
|
| 21 |
def reaction_button(object, reaction = nil) |
|
| 22 |
return unless Setting.reactions_enabled? && object.visible?(User.current) |
|
| 23 | ||
| 24 |
reaction ||= object.reaction_by(User.current) |
|
| 25 | ||
| 26 |
count = object.reaction_count |
|
| 27 |
user_names = object.reaction_user_names |
|
| 28 | ||
| 29 |
tooltip = build_reaction_tooltip(user_names, count) |
|
| 30 | ||
| 31 |
if User.current.logged? |
|
| 32 |
if reaction&.persisted? |
|
| 33 |
reaction_button_reacted(object, reaction, count, tooltip) |
|
| 34 |
else |
|
| 35 |
reaction_button_not_reacted(object, count, tooltip) |
|
| 36 |
end |
|
| 37 |
else |
|
| 38 |
reaction_button_readonly(object, count, tooltip) |
|
| 39 |
end |
|
| 40 |
end |
|
| 41 | ||
| 42 |
def reaction_id_for(object) |
|
| 43 |
dom_id(object, :reaction) |
|
| 44 |
end |
|
| 45 | ||
| 46 |
private |
|
| 47 | ||
| 48 |
def reaction_button_reacted(object, reaction, count, tooltip) |
|
| 49 |
reaction_button_wrapper object do |
|
| 50 |
link_to( |
|
| 51 |
sprite_icon('thumb-up-filled', count),
|
|
| 52 |
reaction_path(reaction, object_type: object.class.name, object_id: object), |
|
| 53 |
remote: true, method: :delete, |
|
| 54 |
class: ['icon', 'reaction-button', 'reacted'], |
|
| 55 |
title: tooltip |
|
| 56 |
) |
|
| 57 |
end |
|
| 58 |
end |
|
| 59 | ||
| 60 |
def reaction_button_not_reacted(object, count, tooltip) |
|
| 61 |
reaction_button_wrapper object do |
|
| 62 |
link_to( |
|
| 63 |
sprite_icon('thumb-up', count),
|
|
| 64 |
reactions_path(object_type: object.class.name, object_id: object), |
|
| 65 |
remote: true, method: :post, |
|
| 66 |
class: 'icon reaction-button', |
|
| 67 |
title: tooltip |
|
| 68 |
) |
|
| 69 |
end |
|
| 70 |
end |
|
| 71 | ||
| 72 |
def reaction_button_readonly(object, count, tooltip) |
|
| 73 |
reaction_button_wrapper object do |
|
| 74 |
tag.span(class: 'icon reaction-button', title: tooltip) do |
|
| 75 |
sprite_icon('thumb-up', count)
|
|
| 76 |
end |
|
| 77 |
end |
|
| 78 |
end |
|
| 79 | ||
| 80 |
def reaction_button_wrapper(object, &) |
|
| 81 |
tag.span(data: { 'reaction-button-id': reaction_id_for(object) }, &)
|
|
| 82 |
end |
|
| 83 | ||
| 84 |
def build_reaction_tooltip(user_names, count) |
|
| 85 |
return if count.zero? |
|
| 86 | ||
| 87 |
display_user_names = user_names.dup |
|
| 88 | ||
| 89 |
if count > Redmine::Reaction::DISPLAY_REACTION_USERS_LIMIT |
|
| 90 |
others = count - Redmine::Reaction::DISPLAY_REACTION_USERS_LIMIT |
|
| 91 |
display_user_names << I18n.t(:reaction_text_x_other_users, count: others) |
|
| 92 |
end |
|
| 93 | ||
| 94 |
display_user_names.to_sentence(locale: I18n.locale) |
|
| 95 |
end |
|
| 96 |
end |
|
| app/models/comment.rb | ||
|---|---|---|
| 19 | 19 | |
| 20 | 20 |
class Comment < ApplicationRecord |
| 21 | 21 |
include Redmine::SafeAttributes |
| 22 |
include Redmine::Reaction::Reactable |
|
| 23 | ||
| 22 | 24 |
belongs_to :commented, :polymorphic => true, :counter_cache => true |
| 23 | 25 |
belongs_to :author, :class_name => 'User' |
| 24 | 26 | |
| ... | ... | |
| 28 | 30 | |
| 29 | 31 |
safe_attributes 'comments' |
| 30 | 32 | |
| 33 |
delegate :visible?, to: :commented |
|
| 34 | ||
| 31 | 35 |
def comments=(arg) |
| 32 | 36 |
self.content = arg |
| 33 | 37 |
end |
| app/models/issue.rb | ||
|---|---|---|
| 25 | 25 |
before_validation :clear_disabled_fields |
| 26 | 26 |
before_save :set_parent_id |
| 27 | 27 |
include Redmine::NestedSet::IssueNestedSet |
| 28 |
include Redmine::Reaction::Reactable |
|
| 28 | 29 | |
| 29 | 30 |
belongs_to :project |
| 30 | 31 |
belongs_to :tracker |
| ... | ... | |
| 916 | 917 |
result = journals. |
| 917 | 918 |
preload(:details). |
| 918 | 919 |
preload(:user => :email_address). |
| 919 |
reorder(:created_on, :id).to_a |
|
| 920 |
reorder(:created_on, :id). |
|
| 921 |
load_with_reactions |
|
| 920 | 922 | |
| 921 | 923 |
result.each_with_index {|j, i| j.indice = i + 1}
|
| 922 | 924 | |
| app/models/journal.rb | ||
|---|---|---|
| 19 | 19 | |
| 20 | 20 |
class Journal < ApplicationRecord |
| 21 | 21 |
include Redmine::SafeAttributes |
| 22 |
include Redmine::Reaction::Reactable |
|
| 22 | 23 | |
| 23 | 24 |
belongs_to :journalized, :polymorphic => true |
| 24 | 25 |
# added as a quick fix to allow eager loading of the polymorphic association |
| app/models/message.rb | ||
|---|---|---|
| 19 | 19 | |
| 20 | 20 |
class Message < ApplicationRecord |
| 21 | 21 |
include Redmine::SafeAttributes |
| 22 |
include Redmine::Reaction::Reactable |
|
| 23 | ||
| 22 | 24 |
belongs_to :board |
| 23 | 25 |
belongs_to :author, :class_name => 'User' |
| 24 | 26 |
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
|
| app/models/news.rb | ||
|---|---|---|
| 19 | 19 | |
| 20 | 20 |
class News < ApplicationRecord |
| 21 | 21 |
include Redmine::SafeAttributes |
| 22 |
include Redmine::Reaction::Reactable |
|
| 23 | ||
| 22 | 24 |
belongs_to :project |
| 23 | 25 |
belongs_to :author, :class_name => 'User' |
| 24 | 26 |
has_many :comments, lambda {order("created_on")}, :as => :commented, :dependent => :delete_all
|
| app/models/reaction.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
class Reaction < ApplicationRecord |
|
| 21 |
belongs_to :reactable, polymorphic: true |
|
| 22 |
belongs_to :user |
|
| 23 | ||
| 24 |
validates :reactable_type, inclusion: { in: Redmine::Reaction::REACTABLE_TYPES }
|
|
| 25 | ||
| 26 |
scope :by, ->(user) { where(user: user) }
|
|
| 27 | ||
| 28 |
# Returns a mapping of reactable IDs to an array of user names |
|
| 29 |
# |
|
| 30 |
# Returns: |
|
| 31 |
# {
|
|
| 32 |
# 1 => ["Alice", "Bob"], |
|
| 33 |
# 2 => ["Charlie"], |
|
| 34 |
# ... |
|
| 35 |
# } |
|
| 36 |
def self.users_map_for_reactables(reactable_type, reactable_ids) |
|
| 37 |
reactions = preload(:user) |
|
| 38 |
.select(:reactable_id, :user_id) |
|
| 39 |
.where(reactable_type: reactable_type, reactable_id: reactable_ids) |
|
| 40 |
.order(id: :desc) |
|
| 41 | ||
| 42 |
reactable_user_pairs = reactions.map do |reaction| |
|
| 43 |
[reaction.reactable_id, reaction.user.name] |
|
| 44 |
end |
|
| 45 | ||
| 46 |
# Group by reactable_id and transform values to extract only user name |
|
| 47 |
# [[1, "Alice"], [1, "Bob"], [2, "Charlie"], ...] |
|
| 48 |
# => |
|
| 49 |
# { 1 => ["Alice", "Bob"], 2 => ["Charlie"], ...}
|
|
| 50 |
reactable_user_pairs |
|
| 51 |
.group_by(&:first) |
|
| 52 |
.transform_values { |pairs| pairs.map(&:last) }
|
|
| 53 |
end |
|
| 54 |
end |
|
| app/models/user.rb | ||
|---|---|---|
| 93 | 93 |
has_one :api_token, lambda {where "#{table.name}.action='api'"}, :class_name => 'Token'
|
| 94 | 94 |
has_one :email_address, lambda {where :is_default => true}, :autosave => true
|
| 95 | 95 |
has_many :email_addresses, :dependent => :delete_all |
| 96 |
has_many :reactions, dependent: :delete_all |
|
| 96 | 97 |
belongs_to :auth_source |
| 97 | 98 | |
| 98 | 99 |
scope :logged, lambda {where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}")}
|
| app/views/issues/show.html.erb | ||
|---|---|---|
| 39 | 39 | |
| 40 | 40 |
<div class="subject"> |
| 41 | 41 |
<%= render_issue_subject_with_tree(@issue) %> |
| 42 |
</div> |
|
| 43 | ||
| 44 |
<div class="reaction"> |
|
| 45 |
<%= reaction_button @issue %> |
|
| 42 | 46 |
</div> |
| 43 | 47 |
<p class="author"> |
| 44 | 48 |
<%= authoring @issue.created_on, @issue.author %>. |
| app/views/messages/show.html.erb | ||
|---|---|---|
| 27 | 27 |
<h2><%= avatar(@topic.author) %><%= @topic.subject %></h2> |
| 28 | 28 | |
| 29 | 29 |
<div class="message"> |
| 30 |
<div class="reaction"> |
|
| 31 |
<%= reaction_button @topic %> |
|
| 32 |
</div> |
|
| 30 | 33 |
<p><span class="author"><%= authoring @topic.created_on, @topic.author %></span></p> |
| 31 | 34 |
<div id="message_topic_wiki" class="wiki"> |
| 32 | 35 |
<%= textilizable(@topic, :content) %> |
| ... | ... | |
| 44 | 47 |
<% @replies.each do |message| %> |
| 45 | 48 |
<div class="message reply" id="<%= "message-#{message.id}" %>">
|
| 46 | 49 |
<div class="contextual"> |
| 50 |
<%= reaction_button message %> |
|
| 47 | 51 |
<%= quote_reply( |
| 48 | 52 |
url_for(:action => 'quote', :id => message, :format => 'js'), |
| 49 | 53 |
"#message-#{message.id} .wiki",
|
| app/views/news/show.html.erb | ||
|---|---|---|
| 22 | 22 |
</div> |
| 23 | 23 |
<% end %> |
| 24 | 24 | |
| 25 |
<p><% unless @news.summary.blank? %><em><%= @news.summary %></em><br /><% end %> |
|
| 26 |
<span class="author"><%= authoring @news.created_on, @news.author %></span></p> |
|
| 27 |
<div class="wiki"> |
|
| 28 |
<%= textilizable(@news, :description) %> |
|
| 25 |
<div class="news"> |
|
| 26 |
<div class="reaction"> |
|
| 27 |
<%= reaction_button @news %> |
|
| 28 |
</div> |
|
| 29 |
<p><% unless @news.summary.blank? %><em><%= @news.summary %></em><br /><% end %> |
|
| 30 |
<span class="author"><%= authoring @news.created_on, @news.author %></span></p> |
|
| 31 |
<div class="wiki"> |
|
| 32 |
<%= textilizable(@news, :description) %> |
|
| 33 |
</div> |
|
| 34 |
<%= link_to_attachments @news %> |
|
| 29 | 35 |
</div> |
| 30 |
<%= link_to_attachments @news %> |
|
| 31 | 36 |
<br /> |
| 32 | 37 | |
| 33 | 38 |
<div id="comments" style="margin-bottom:16px;"> |
| ... | ... | |
| 38 | 43 |
<% @comments.each do |comment| %> |
| 39 | 44 |
<% next if comment.new_record? %> |
| 40 | 45 |
<div class="contextual"> |
| 46 |
<%= reaction_button comment %> |
|
| 41 | 47 |
<%= link_to_if_authorized sprite_icon('del', l(:button_delete)), { :controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
|
| 42 | 48 |
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,
|
| 43 | 49 |
:title => l(:button_delete), |
| app/views/reactions/_replace_button.js.erb | ||
|---|---|---|
| 1 |
(() => {
|
|
| 2 |
const button = $('[data-reaction-button-id=<%= reaction_id_for @object %>]');
|
|
| 3 | ||
| 4 |
removeHoverTooltips(button); |
|
| 5 |
button.html($('<%=j reaction_button @object, @reaction %>').children());
|
|
| 6 |
setupHoverTooltips(button); |
|
| 7 |
})(); |
|
| app/views/reactions/create.js.erb | ||
|---|---|---|
| 1 |
<%= render 'replace_button' %> |
|
| app/views/reactions/destroy.js.erb | ||
|---|---|---|
| 1 |
<%= render 'replace_button' %> |
|
| app/views/settings/_general.html.erb | ||
|---|---|---|
| 37 | 37 | |
| 38 | 38 |
<p><%= setting_text_field :feeds_limit, :size => 6 %></p> |
| 39 | 39 | |
| 40 |
<p> |
|
| 41 |
<%= setting_check_box :reactions_enabled %> |
|
| 42 |
<em class="info"> |
|
| 43 |
<%= l(:reaction_text_enabling_reactions) %> |
|
| 44 |
</em> |
|
| 45 |
</p> |
|
| 46 | ||
| 40 | 47 |
<%= call_hook(:view_settings_general_form) %> |
| 41 | 48 |
</div> |
| 42 | 49 | |
| config/icon_source.yml | ||
|---|---|---|
| 221 | 221 |
- name: unwatch |
| 222 | 222 |
svg: eye-off |
| 223 | 223 |
- name: copy-pre-content |
| 224 |
svg: clipboard |
|
| 224 |
svg: clipboard |
|
| 225 |
- name: thumb-up |
|
| 226 |
svg: thumb-up |
|
| 227 |
- name: thumb-up-filled |
|
| 228 |
svg: thumb-up |
|
| 229 |
style: filled |
|
| config/locales/en.yml | ||
|---|---|---|
| 528 | 528 |
setting_twofa: Two-factor authentication |
| 529 | 529 |
setting_related_issues_default_columns: Related and sub issues list defaults |
| 530 | 530 |
setting_display_related_issues_table_headers: Show table headers |
| 531 |
setting_reactions_enabled: Enable reactions |
|
| 531 | 532 | |
| 532 | 533 |
permission_add_project: Create project |
| 533 | 534 |
permission_add_subprojects: Create subprojects |
| ... | ... | |
| 1432 | 1433 |
text_project_destroy_enter_identifier: "To confirm, please enter the project's identifier (%{identifier}) below."
|
| 1433 | 1434 |
field_name_or_email_or_login: Name, email or login |
| 1434 | 1435 |
setting_wiki_tablesort_enabled: Javascript based table sorting in wiki content |
| 1436 | ||
| 1437 |
reaction_text_enabling_reactions: "This enables reactions in issues, forums, and news." |
|
| 1438 |
reaction_text_x_other_users: |
|
| 1439 |
one: "1 other" |
|
| 1440 |
other: "%{count} others"
|
|
| config/locales/ja.yml | ||
|---|---|---|
| 1457 | 1457 |
setting_related_issues_default_columns: 関連するチケットと子チケットの一覧で表示する項目 |
| 1458 | 1458 |
setting_display_related_issues_table_headers: テーブルヘッダを表示 |
| 1459 | 1459 |
error_can_not_remove_role_reason_members_html: "<p>以下のプロジェクトにこのロールのメンバーがいます:<br>%{projects}</p>"
|
| 1460 |
setting_reactions_enabled: リアクション機能を有効にする |
|
| 1461 |
reaction_text_enabling_reactions: "チケット、フォーラム、ニュースでリアクション機能を有効にします。" |
|
| 1462 |
reaction_text_x_other_users: |
|
| 1463 |
one: 他1人 |
|
| 1464 |
other: "他%{count}人"
|
|
| config/routes.rb | ||
|---|---|---|
| 61 | 61 |
end |
| 62 | 62 |
end |
| 63 | 63 | |
| 64 |
resources :reactions, only: [:create, :destroy] |
|
| 65 | ||
| 64 | 66 |
get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt' |
| 65 | 67 |
get '/issues/gantt', :to => 'gantts#show' |
| 66 | 68 | |
| config/settings.yml | ||
|---|---|---|
| 363 | 363 |
default: 1 |
| 364 | 364 |
wiki_tablesort_enabled: |
| 365 | 365 |
default: 1 |
| 366 |
reactions_enabled: |
|
| 367 |
default: 1 |
|
| db/migrate/20250423065135_create_reactions.rb | ||
|---|---|---|
| 1 |
class CreateReactions < ActiveRecord::Migration[7.2] |
|
| 2 |
def change |
|
| 3 |
create_table :reactions do |t| |
|
| 4 |
t.references :reactable, polymorphic: true, null: false |
|
| 5 |
t.references :user, null: false |
|
| 6 |
t.timestamps null: false |
|
| 7 |
end |
|
| 8 |
add_index :reactions, [:reactable_type, :reactable_id, :user_id], unique: true |
|
| 9 |
add_index :reactions, [:reactable_type, :reactable_id, :id] |
|
| 10 |
end |
|
| 11 |
end |
|
| lib/redmine/reaction.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
module Redmine |
|
| 21 |
module Reaction |
|
| 22 |
# Types of objects that can have reactions |
|
| 23 |
REACTABLE_TYPES = %w(Journal Issue Message News Comment) |
|
| 24 | ||
| 25 |
# Maximum number of users to display in the reaction button tooltip |
|
| 26 |
DISPLAY_REACTION_USERS_LIMIT = 10 |
|
| 27 | ||
| 28 |
module Reactable |
|
| 29 |
extend ActiveSupport::Concern |
|
| 30 | ||
| 31 |
included do |
|
| 32 |
has_many :reactions, -> { order(id: :desc) }, as: :reactable, dependent: :delete_all
|
|
| 33 |
has_many :reaction_users, through: :reactions, source: :user |
|
| 34 | ||
| 35 |
attr_writer :reaction_user_names, :reaction_count |
|
| 36 |
end |
|
| 37 | ||
| 38 |
class_methods do |
|
| 39 |
def load_with_reactions |
|
| 40 |
objects = all.to_a |
|
| 41 | ||
| 42 |
return objects unless Setting.reactions_enabled? |
|
| 43 | ||
| 44 |
object_users_map = ::Reaction.users_map_for_reactables(self.name, objects.map(&:id)) |
|
| 45 | ||
| 46 |
objects.each do |object| |
|
| 47 |
all_user_names = object_users_map[object.id] || [] |
|
| 48 | ||
| 49 |
object.reaction_count = all_user_names.size |
|
| 50 |
object.reaction_user_names = all_user_names.take(DISPLAY_REACTION_USERS_LIMIT) |
|
| 51 |
end |
|
| 52 |
objects |
|
| 53 |
end |
|
| 54 |
end |
|
| 55 | ||
| 56 |
def reaction_user_names |
|
| 57 |
@reaction_user_names || reaction_users.take(DISPLAY_REACTION_USERS_LIMIT).map(&:name) |
|
| 58 |
end |
|
| 59 | ||
| 60 |
def reaction_count |
|
| 61 |
@reaction_count || reaction_users.size |
|
| 62 |
end |
|
| 63 | ||
| 64 |
def reaction_by(user) |
|
| 65 |
if reactions.loaded? |
|
| 66 |
reactions.find { _1.user_id == user.id }
|
|
| 67 |
else |
|
| 68 |
reactions.find_by(user: user) |
|
| 69 |
end |
|
| 70 |
end |
|
| 71 |
end |
|
| 72 |
end |
|
| 73 |
end |
|
| test/fixtures/reactions.yml | ||
|---|---|---|
| 1 |
--- |
|
| 2 |
reaction_001: |
|
| 3 |
id: 1 |
|
| 4 |
reactable_type: Issue |
|
| 5 |
reactable_id: 1 |
|
| 6 |
user_id: 1 |
|
| 7 |
reaction_002: |
|
| 8 |
id: 2 |
|
| 9 |
reactable_type: Issue |
|
| 10 |
reactable_id: 1 |
|
| 11 |
user_id: 2 |
|
| 12 |
reaction_003: |
|
| 13 |
id: 3 |
|
| 14 |
reactable_type: Issue |
|
| 15 |
reactable_id: 1 |
|
| 16 |
user_id: 3 |
|
| 17 |
reaction_004: |
|
| 18 |
id: 4 |
|
| 19 |
reactable_type: Journal |
|
| 20 |
reactable_id: 1 |
|
| 21 |
user_id: 2 |
|
| 22 |
reaction_005: |
|
| 23 |
id: 5 |
|
| 24 |
reactable_type: Issue |
|
| 25 |
reactable_id: 6 |
|
| 26 |
user_id: 2 |
|
| 27 |
reaction_006: |
|
| 28 |
id: 6 |
|
| 29 |
reactable_type: Journal |
|
| 30 |
reactable_id: 4 |
|
| 31 |
user_id: 2 |
|
| 32 |
reaction_007: |
|
| 33 |
id: 7 |
|
| 34 |
reactable_type: News |
|
| 35 |
reactable_id: 1 |
|
| 36 |
user_id: 1 |
|
| 37 |
reaction_008: |
|
| 38 |
id: 8 |
|
| 39 |
reactable_type: Comment |
|
| 40 |
reactable_id: 1 |
|
| 41 |
user_id: 2 |
|
| 42 |
reaction_009: |
|
| 43 |
id: 9 |
|
| 44 |
reactable_type: Message |
|
| 45 |
reactable_id: 7 |
|
| 46 |
user_id: 2 |
|
| 47 |
reaction_010: |
|
| 48 |
id: 10 |
|
| 49 |
reactable_type: News |
|
| 50 |
reactable_id: 3 |
|
| 51 |
user_id: 2 |
|
| test/functional/issues_controller_test.rb | ||
|---|---|---|
| 3331 | 3331 |
assert_select 'span.badge.badge-private', text: 'Private' |
| 3332 | 3332 |
end |
| 3333 | 3333 | |
| 3334 |
def test_show_should_display_reactions |
|
| 3335 |
@request.session[:user_id] = nil |
|
| 3336 | ||
| 3337 |
get :show, params: { id: 1 }
|
|
| 3338 | ||
| 3339 |
assert_response :success |
|
| 3340 |
assert_select 'span[data-reaction-button-id=reaction_issue_1] span.reaction-button' do |
|
| 3341 |
assert_select 'span.icon-label', '3' |
|
| 3342 |
end |
|
| 3343 |
assert_select 'span[data-reaction-button-id=reaction_journal_1] span.reaction-button' |
|
| 3344 |
assert_select 'span[data-reaction-button-id=reaction_journal_2] span.reaction-button' |
|
| 3345 | ||
| 3346 |
# Should not display reactions when reactions feature is disabled. |
|
| 3347 |
Setting.reactions_enabled = false |
|
| 3348 |
get :show, params: { id: 1 }
|
|
| 3349 | ||
| 3350 |
assert_response :success |
|
| 3351 |
assert_select 'span[data-reaction-button-id]', false |
|
| 3352 |
end |
|
| 3353 | ||
| 3334 | 3354 |
def test_show_should_not_display_edit_attachment_icon_for_user_without_edit_issue_permission_on_tracker |
| 3335 | 3355 |
role = Role.find(2) |
| 3336 | 3356 |
role.set_permission_trackers 'edit_issues', [2, 3] |
| test/functional/messages_controller_test.rb | ||
|---|---|---|
| 123 | 123 |
assert_select 'h3', {text: /Watchers \(\d*\)/, count: 0}
|
| 124 | 124 |
end |
| 125 | 125 | |
| 126 |
def test_show_should_display_reactions |
|
| 127 |
@request.session[:user_id] = 2 |
|
| 128 | ||
| 129 |
get :show, params: { board_id: 1, id: 4 }
|
|
| 130 | ||
| 131 |
assert_response :success |
|
| 132 |
assert_select 'span[data-reaction-button-id=reaction_message_4] a.reaction-button' do |
|
| 133 |
assert_select 'svg use[href*=thumb-up]' |
|
| 134 |
end |
|
| 135 |
assert_select 'span[data-reaction-button-id=reaction_message_5] a.reaction-button' |
|
| 136 |
assert_select 'span[data-reaction-button-id=reaction_message_6] a.reaction-button' |
|
| 137 | ||
| 138 |
# Should not display reactions when reactions feature is disabled. |
|
| 139 |
Setting.reactions_enabled = false |
|
| 140 |
get :show, params: { board_id: 1, id: 4 }
|
|
| 141 | ||
| 142 |
assert_response :success |
|
| 143 |
assert_select 'span[data-reaction-button-id]', false |
|
| 144 |
end |
|
| 145 | ||
| 126 | 146 |
def test_get_new |
| 127 | 147 |
@request.session[:user_id] = 2 |
| 128 | 148 |
get(:new, :params => {:board_id => 1})
|
| test/functional/news_controller_test.rb | ||
|---|---|---|
| 106 | 106 |
assert_response :not_found |
| 107 | 107 |
end |
| 108 | 108 | |
| 109 |
def test_show_should_display_reactions |
|
| 110 |
@request.session[:user_id] = 1 |
|
| 111 | ||
| 112 |
get :show, params: { id: 1 }
|
|
| 113 |
assert_response :success |
|
| 114 |
assert_select 'span[data-reaction-button-id=reaction_news_1] a.reaction-button.reacted' |
|
| 115 |
assert_select 'span[data-reaction-button-id=reaction_comment_1] a.reaction-button' |
|
| 116 | ||
| 117 |
# Should not display reactions when reactions feature is disabled. |
|
| 118 |
Setting.reactions_enabled = false |
|
| 119 |
get :show, params: { id: 1 }
|
|
| 120 |
assert_response :success |
|
| 121 |
assert_select 'span[data-reaction-button-id]', false |
|
| 122 |
end |
|
| 123 | ||
| 109 | 124 |
def test_get_new_with_project_id |
| 110 | 125 |
@request.session[:user_id] = 2 |
| 111 | 126 |
get(:new, :params => {:project_id => 1})
|
| test/functional/reactions_controller_test.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
require_relative '../test_helper' |
|
| 21 | ||
| 22 |
class ReactionsControllerTest < Redmine::ControllerTest |
|
| 23 |
def setup |
|
| 24 |
Setting.reactions_enabled = '1' |
|
| 25 |
# jsmith |
|
| 26 |
@request.session[:user_id] = users(:users_002).id |
|
| 27 |
end |
|
| 28 | ||
| 29 |
test 'create for issue' do |
|
| 30 |
issue = issues(:issues_002) |
|
| 31 | ||
| 32 |
assert_difference( |
|
| 33 |
->{ Reaction.count } => 1,
|
|
| 34 |
->{ issue.reactions.by(users(:users_002)).count } => 1
|
|
| 35 |
) do |
|
| 36 |
post :create, params: {
|
|
| 37 |
object_type: 'Issue', |
|
| 38 |
object_id: issue.id |
|
| 39 |
}, xhr: true |
|
| 40 |
end |
|
| 41 | ||
| 42 |
assert_response :success |
|
| 43 |
end |
|
| 44 | ||
| 45 |
test 'create for journal' do |
|
| 46 |
journal = journals(:journals_005) |
|
| 47 | ||
| 48 |
assert_difference( |
|
| 49 |
->{ Reaction.count } => 1,
|
|
| 50 |
->{ journal.reactions.by(users(:users_002)).count } => 1
|
|
| 51 |
) do |
|
| 52 |
post :create, params: {
|
|
| 53 |
object_type: 'Journal', |
|
| 54 |
object_id: journal.id |
|
| 55 |
}, xhr: true |
|
| 56 |
end |
|
| 57 | ||
| 58 |
assert_response :success |
|
| 59 |
end |
|
| 60 | ||
| 61 |
test 'create for news' do |
|
| 62 |
news = news(:news_002) |
|
| 63 | ||
| 64 |
assert_difference( |
|
| 65 |
->{ Reaction.count } => 1,
|
|
| 66 |
->{ news.reactions.by(users(:users_002)).count } => 1
|
|
| 67 |
) do |
|
| 68 |
post :create, params: {
|
|
| 69 |
object_type: 'News', |
|
| 70 |
object_id: news.id |
|
| 71 |
}, xhr: true |
|
| 72 |
end |
|
| 73 | ||
| 74 |
assert_response :success |
|
| 75 |
end |
|
| 76 | ||
| 77 |
test 'create reaction for comment' do |
|
| 78 |
comment = comments(:comments_002) |
|
| 79 | ||
| 80 |
assert_difference( |
|
| 81 |
->{ Reaction.count } => 1,
|
|
| 82 |
->{ comment.reactions.by(users(:users_002)).count } => 1
|
|
| 83 |
) do |
|
| 84 |
post :create, params: {
|
|
| 85 |
object_type: 'Comment', |
|
| 86 |
object_id: comment.id |
|
| 87 |
}, xhr: true |
|
| 88 |
end |
|
| 89 | ||
| 90 |
assert_response :success |
|
| 91 |
end |
|
| 92 | ||
| 93 |
test 'create for message' do |
|
| 94 |
message = messages(:messages_001) |
|
| 95 | ||
| 96 |
assert_difference( |
|
| 97 |
->{ Reaction.count } => 1,
|
|
| 98 |
->{ message.reactions.by(users(:users_002)).count } => 1
|
|
| 99 |
) do |
|
| 100 |
post :create, params: {
|
|
| 101 |
object_type: 'Message', |
|
| 102 |
object_id: message.id |
|
| 103 |
}, xhr: true |
|
| 104 |
end |
|
| 105 | ||
| 106 |
assert_response :success |
|
| 107 |
end |
|
| 108 | ||
| 109 |
test 'destroy for issue' do |
|
| 110 |
reaction = reactions(:reaction_005) |
|
| 111 | ||
| 112 |
assert_difference 'Reaction.count', -1 do |
|
| 113 |
delete :destroy, params: {
|
|
| 114 |
id: reaction.id, |
|
| 115 |
# Issue (id=6) |
|
| 116 |
object_type: reaction.reactable_type, |
|
| 117 |
object_id: reaction.reactable_id |
|
| 118 |
}, xhr: true |
|
| 119 |
end |
|
| 120 | ||
| 121 |
assert_response :success |
|
| 122 |
assert_not Reaction.exists?(reaction.id) |
|
| 123 |
end |
|
| 124 | ||
| 125 |
test 'destroy for journal' do |
|
| 126 |
reaction = reactions(:reaction_006) |
|
| 127 | ||
| 128 |
assert_difference 'Reaction.count', -1 do |
|
| 129 |
delete :destroy, params: {
|
|
| 130 |
id: reaction.id, |
|
| 131 |
object_type: reaction.reactable_type, |
|
| 132 |
object_id: reaction.reactable_id |
|
| 133 |
}, xhr: true |
|
| 134 |
end |
|
| 135 | ||
| 136 |
assert_response :success |
|
| 137 |
assert_not Reaction.exists?(reaction.id) |
|
| 138 |
end |
|
| 139 | ||
| 140 |
test 'destroy for news' do |
|
| 141 |
# For News(id=3) |
|
| 142 |
reaction = reactions(:reaction_010) |
|
| 143 | ||
| 144 |
assert_difference 'Reaction.count', -1 do |
|
| 145 |
delete :destroy, params: {
|
|
| 146 |
id: reaction.id, |
|
| 147 |
object_type: reaction.reactable_type, |
|
| 148 |
object_id: reaction.reactable_id |
|
| 149 |
}, xhr: true |
|
| 150 |
end |
|
| 151 | ||
| 152 |
assert_response :success |
|
| 153 |
assert_not Reaction.exists?(reaction.id) |
|
| 154 |
end |
|
| 155 | ||
| 156 |
test 'destroy for comment' do |
|
| 157 |
# For Comment(id=1) |
|
| 158 |
reaction = reactions(:reaction_008) |
|
| 159 | ||
| 160 |
assert_difference 'Reaction.count', -1 do |
|
| 161 |
delete :destroy, params: {
|
|
| 162 |
id: reaction.id, |
|
| 163 |
object_type: reaction.reactable_type, |
|
| 164 |
object_id: reaction.reactable_id |
|
| 165 |
}, xhr: true |
|
| 166 |
end |
|
| 167 | ||
| 168 |
assert_response :success |
|
| 169 |
assert_not Reaction.exists?(reaction.id) |
|
| 170 |
end |
|
| 171 | ||
| 172 |
test 'destroy for message' do |
|
| 173 |
reaction = reactions(:reaction_009) |
|
| 174 | ||
| 175 |
assert_difference 'Reaction.count', -1 do |
|
| 176 |
delete :destroy, params: {
|
|
| 177 |
id: reaction.id, |
|
| 178 |
object_type: reaction.reactable_type, |
|
| 179 |
object_id: reaction.reactable_id |
|
| 180 |
}, xhr: true |
|
| 181 |
end |
|
| 182 | ||
| 183 |
assert_response :success |
|
| 184 |
assert_not Reaction.exists?(reaction.id) |
|
| 185 |
end |
|
| 186 | ||
| 187 |
test 'create should respond with 403 when feature is disabled' do |
|
| 188 |
Setting.reactions_enabled = '0' |
|
| 189 |
# admin |
|
| 190 |
@request.session[:user_id] = users(:users_001).id |
|
| 191 | ||
| 192 |
assert_no_difference 'Reaction.count' do |
|
| 193 |
post :create, params: {
|
|
| 194 |
object_type: 'Issue', |
|
| 195 |
object_id: issues(:issues_002).id |
|
| 196 |
}, xhr: true |
|
| 197 |
end |
|
| 198 |
assert_response :forbidden |
|
| 199 |
end |
|
| 200 | ||
| 201 |
test 'destroy should respond with 403 when feature is disabled' do |
|
| 202 |
Setting.reactions_enabled = '0' |
|
| 203 |
# admin |
|
| 204 |
@request.session[:user_id] = users(:users_001).id |
|
| 205 | ||
| 206 |
reaction = reactions(:reaction_001) |
|
| 207 |
assert_no_difference 'Reaction.count' do |
|
| 208 |
delete :destroy, params: {
|
|
| 209 |
id: reaction.id, |
|
| 210 |
object_type: reaction.reactable_type, |
|
| 211 |
object_id: reaction.reactable_id |
|
| 212 |
}, xhr: true |
|
| 213 |
end |
|
| 214 |
assert_response :forbidden |
|
| 215 |
end |
|
| 216 | ||
| 217 |
test 'create by anonymous user should respond with 403' do |
|
| 218 |
@request.session[:user_id] = nil |
|
| 219 | ||
| 220 |
assert_no_difference 'Reaction.count' do |
|
| 221 |
post :create, params: {
|
|
| 222 |
object_type: 'Issue', |
|
| 223 |
# Issue(id=1) is an issue in a public project |
|
| 224 |
object_id: issues(:issues_001).id |
|
| 225 |
}, xhr: true |
|
| 226 |
end |
|
| 227 | ||
| 228 |
assert_response :unauthorized |
|
| 229 |
end |
|
| 230 | ||
| 231 |
test 'destroy by anonymous user should respond with 401' do |
|
| 232 |
@request.session[:user_id] = nil |
|
| 233 | ||
| 234 |
reaction = reactions(:reaction_002) |
|
| 235 |
assert_no_difference 'Reaction.count' do |
|
| 236 |
delete :destroy, params: {
|
|
| 237 |
id: reaction.id, |
|
| 238 |
object_type: reaction.reactable_type, |
|
| 239 |
object_id: reaction.reactable_id |
|
| 240 |
}, xhr: true |
|
| 241 |
end |
|
| 242 | ||
| 243 |
assert_response :unauthorized |
|
| 244 |
end |
|
| 245 | ||
| 246 |
test 'create when reaction already exists should not create a new reaction and succeed' do |
|
| 247 |
assert_no_difference 'Reaction.count' do |
|
| 248 |
post :create, params: {
|
|
| 249 |
object_type: 'Comment', |
|
| 250 |
# user(jsmith) has already reacted to Comment(id=1) |
|
| 251 |
object_id: comments(:comments_001).id |
|
| 252 |
}, xhr: true |
|
| 253 |
end |
|
| 254 | ||
| 255 |
assert_response :success |
|
| 256 |
end |
|
| 257 | ||
| 258 |
test 'destroy another user reaction should not destroy the reaction and succeed' do |
|
| 259 |
# admin user's reaction |
|
| 260 |
reaction = reactions(:reaction_001) |
|
| 261 | ||
| 262 |
assert_no_difference 'Reaction.count' do |
|
| 263 |
delete :destroy, params: {
|
|
| 264 |
id: reaction.id, |
|
| 265 |
object_type: reaction.reactable_type, |
|
| 266 |
object_id: reaction.reactable_id |
|
| 267 |
}, xhr: true |
|
| 268 |
end |
|
| 269 | ||
| 270 |
assert_response :success |
|
| 271 |
end |
|
| 272 | ||
| 273 |
test 'destroy nonexistent reaction' do |
|
| 274 |
# For Journal(id=4) |
|
| 275 |
reaction = reactions(:reaction_006) |
|
| 276 |
reaction.destroy! |
|
| 277 | ||
| 278 |
assert_not Reaction.exists?(reaction.id) |
|
| 279 | ||
| 280 |
assert_no_difference 'Reaction.count' do |
|
| 281 |
delete :destroy, params: {
|
|
| 282 |
id: reaction.id, |
|
| 283 |
object_type: reaction.reactable_type, |
|
| 284 |
object_id: reaction.reactable_id |
|
| 285 |
}, xhr: true |
|
| 286 |
end |
|
| 287 | ||
| 288 |
assert_response :success |
|
| 289 |
end |
|
| 290 | ||
| 291 |
test 'create with invalid object type should respond with 403' do |
|
| 292 |
# admin |
|
| 293 |
@request.session[:user_id] = users(:users_001).id |
|
| 294 | ||
| 295 |
post :create, params: {
|
|
| 296 |
object_type: 'InvalidType', |
|
| 297 |
object_id: 1 |
|
| 298 |
}, xhr: true |
|
| 299 | ||
| 300 |
assert_response :forbidden |
|
| 301 |
end |
|
| 302 | ||
| 303 |
test 'create without permission to view should respond with 403' do |
|
| 304 |
# dlopper |
|
| 305 |
@request.session[:user_id] = users(:users_003).id |
|
| 306 | ||
| 307 |
assert_no_difference 'Reaction.count' do |
|
| 308 |
post :create, params: {
|
|
| 309 |
object_type: 'Issue', |
|
| 310 |
# dlopper is not a member of the project where the issue (id=4) belongs. |
|
| 311 |
object_id: issues(:issues_004).id |
|
| 312 |
}, xhr: true |
|
| 313 |
end |
|
| 314 | ||
| 315 |
assert_response :forbidden |
|
| 316 |
end |
|
| 317 | ||
| 318 |
test 'destroy without permission to view should respond with 403' do |
|
| 319 |
# dlopper |
|
| 320 |
@request.session[:user_id] = users(:users_003).id |
|
| 321 | ||
| 322 |
# For Issue(id=6) |
|
| 323 |
reaction = reactions(:reaction_005) |
|
| 324 | ||
| 325 |
assert_no_difference 'Reaction.count' do |
|
| 326 |
delete :destroy, params: {
|
|
| 327 |
id: reaction.id, |
|
| 328 |
object_type: reaction.reactable_type, |
|
| 329 |
object_id: reaction.reactable_id |
|
| 330 |
}, xhr: true |
|
| 331 |
end |
|
| 332 | ||
| 333 |
assert_response :forbidden |
|
| 334 |
end |
|
| 335 |
end |
|
| test/helpers/reactions_helper_test.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
require_relative '../test_helper' |
|
| 21 | ||
| 22 |
class ReactionsHelperTest < ActionView::TestCase |
|
| 23 |
include ReactionsHelper |
|
| 24 | ||
| 25 |
setup do |
|
| 26 |
User.current = users(:users_002) |
|
| 27 |
Setting.reactions_enabled = '1' |
|
| 28 |
end |
|
| 29 | ||
| 30 |
test 'reaction_id_for generates a DOM id' do |
|
| 31 |
assert_equal "reaction_issue_1", reaction_id_for(issues(:issues_001)) |
|
| 32 |
end |
|
| 33 | ||
| 34 |
test 'reaction_button returns nil when feature is disabled' do |
|
| 35 |
Setting.reactions_enabled = '0' |
|
| 36 | ||
| 37 |
assert_nil reaction_button(issues(:issues_004)) |
|
| 38 |
end |
|
| 39 | ||
| 40 |
test 'reaction_button returns nil when object not visible' do |
|
| 41 |
User.current = users(:users_003) |
|
| 42 | ||
| 43 |
assert_nil reaction_button(issues(:issues_004)) |
|
| 44 |
end |
|
| 45 | ||
| 46 |
test 'reaction_button for anonymous users shows static icon' do |
|
| 47 |
User.current = nil |
|
| 48 | ||
| 49 |
result = reaction_button(journals(:journals_001)) |
|
| 50 | ||
| 51 |
assert_select_in result, 'span.reaction-button[title=?]', 'John Smith' |
|
| 52 |
assert_select_in result, 'a.reaction-button', false |
|
| 53 |
end |
|
| 54 | ||
| 55 |
test 'reaction_button includes no tooltip when the object has no reactions' do |
|
| 56 |
issue = issues(:issues_002) # Issue without reactions |
|
| 57 |
result = reaction_button(issue) |
|
| 58 | ||
| 59 |
assert_select_in result, 'span.reaction-button[title]', false |
|
| 60 |
end |
|
| 61 | ||
| 62 |
test 'reaction_button includes tooltip with all usernames when reactions are 10 or fewer' do |
|
| 63 |
issue = issues(:issues_002) |
|
| 64 | ||
| 65 |
reactions = build_reactions(10) |
|
| 66 |
issue.reactions += reactions |
|
| 67 | ||
| 68 |
result = with_locale 'en' do |
|
| 69 |
reaction_button(issue) |
|
| 70 |
end |
|
| 71 | ||
| 72 |
# The tooltip should display usernames in order of newest reactions. |
|
| 73 |
expected_tooltip = 'Bob9 Doe, Bob8 Doe, Bob7 Doe, Bob6 Doe, Bob5 Doe, ' \ |
|
| 74 |
'Bob4 Doe, Bob3 Doe, Bob2 Doe, Bob1 Doe, and Bob0 Doe' |
|
| 75 | ||
| 76 |
assert_select_in result, 'a.reaction-button[title=?]', expected_tooltip |
|
| 77 |
end |
|
| 78 | ||
| 79 |
test 'reaction_button includes tooltip with 10 usernames and others count when reactions exceed 10' do |
|
| 80 |
issue = issues(:issues_002) |
|
| 81 | ||
| 82 |
reactions = build_reactions(11) |
|
| 83 |
issue.reactions += reactions |
|
| 84 | ||
| 85 |
result = with_locale 'en' do |
|
| 86 |
reaction_button(issue) |
|
| 87 |
end |
|
| 88 | ||
| 89 |
expected_tooltip = 'Bob10 Doe, Bob9 Doe, Bob8 Doe, Bob7 Doe, Bob6 Doe, ' \ |
|
| 90 |
'Bob5 Doe, Bob4 Doe, Bob3 Doe, Bob2 Doe, Bob1 Doe, and 1 other' |
|
| 91 | ||
| 92 |
assert_select_in result, 'a.reaction-button[title=?]', expected_tooltip |
|
| 93 |
end |
|
| 94 | ||
| 95 |
test 'reaction_button for reacted object' do |
|
| 96 |
issue = issues(:issues_001) |
|
| 97 |
reaction = issue.reactions.find_by(user: User.current) |
|
| 98 | ||
| 99 |
result = with_locale('en') do
|
|
| 100 |
reaction_button(issue, reaction) |
|
| 101 |
end |
|
| 102 |
tooltip = 'Dave Lopper, John Smith, and Redmine Admin' |
|
| 103 | ||
| 104 |
assert_select_in result, 'span[data-reaction-button-id=?]', 'reaction_issue_1' do |
|
| 105 |
href = reaction_path(reaction, object_type: 'Issue', object_id: 1) |
|
| 106 | ||
| 107 |
assert_select 'a.icon.reaction-button.reacted[href=?]', href do |
|
| 108 |
assert_select 'use[href*=?]', 'thumb-up-filled' |
|
| 109 |
assert_select 'span.icon-label', '3' |
|
| 110 |
end |
|
| 111 | ||
| 112 |
assert_select 'span.reaction-button', false |
|
| 113 |
end |
|
| 114 |
end |
|
| 115 | ||
| 116 |
test 'reaction_button for non-reacted object' do |
|
| 117 |
User.current = users(:users_004) |
|
| 118 | ||
| 119 |
issue = issues(:issues_001) |
|
| 120 |
reaction = issue.reactions.find_by(user: User.current) |
|
| 121 | ||
| 122 |
result = with_locale('en') do
|
|
| 123 |
reaction_button(issue, reaction) |
|
| 124 |
end |
|
| 125 |
tooltip = 'Dave Lopper, John Smith, and Redmine Admin' |
|
| 126 | ||
| 127 |
assert_select_in result, 'span[data-reaction-button-id=?]', 'reaction_issue_1' do |
|
| 128 |
href = reactions_path(object_type: 'Issue', object_id: 1) |
|
| 129 | ||
| 130 |
assert_select 'a.icon.reaction-button[href=?]', href do |
|
| 131 |
assert_select 'use[href*=?]', 'thumb-up' |
|
| 132 |
assert_select 'span.icon-label', '3' |
|
| 133 |
end |
|
| 134 | ||
| 135 |
assert_select 'span.reaction-button', false |
|
| 136 |
end |
|
| 137 |
end |
|
| 138 | ||
| 139 |
private |
|
| 140 | ||
| 141 |
def build_reactions(count) |
|
| 142 |
Array.new(count) do |i| |
|
| 143 |
Reaction.new(user: User.generate!(firstname: "Bob#{i}"))
|
|
| 144 |
end |
|
| 145 |
end |
|
| 146 |
end |
|
| test/system/reactions_test.rb | ||
|---|---|---|
| 1 |
# frozen_string_literal: true |
|
| 2 | ||
| 3 |
# Redmine - project management software |
|
| 4 |
# Copyright (C) 2006- Jean-Philippe Lang |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; either version 2 |
|
| 9 |
# of the License, or (at your option) any later version. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 19 | ||
| 20 |
require_relative '../application_system_test_case' |
|
| 21 | ||
| 22 |
class ReactionsSystemTest < ApplicationSystemTestCase |
|
| 23 |
def test_react_to_issue |
|
| 24 |
log_user('jsmith', 'jsmith')
|
|
| 25 | ||
| 26 |
issue = issues(:issues_002) |
|
| 27 | ||
| 28 |
with_settings(reactions_enabled: '1') do |
|
| 29 |
visit '/issues/2' |
|
| 30 |
reaction_button = find("div.issue.details [data-reaction-button-id=\"reaction_issue_#{issue.id}\"]")
|
|
| 31 |
assert_reaction_add_and_remove(reaction_button, issue) |
|
| 32 |
end |
|
| 33 |
end |
|
| 34 | ||
| 35 |
def test_react_to_journal |
|
| 36 |
log_user('jsmith', 'jsmith')
|
|
| 37 | ||
| 38 |
journal = journals(:journals_002) |
|
| 39 | ||
| 40 |
with_settings(reactions_enabled: '1') do |
|
| 41 |
visit '/issues/1' |
|
| 42 |
reaction_button = find("[data-reaction-button-id=\"reaction_journal_#{journal.id}\"]")
|
|
| 43 |
assert_reaction_add_and_remove(reaction_button, journal.reload) |
|
| 44 |
end |
|
| 45 |
end |
|
| 46 | ||
| 47 |
def test_react_to_forum_reply |
|
| 48 |
log_user('jsmith', 'jsmith')
|
|
| 49 | ||
| 50 |
reply_message = messages(:messages_002) # reply to message_001 |
|
| 51 | ||
| 52 |
with_settings(reactions_enabled: '1') do |
|
| 53 |
visit 'boards/1/topics/1' |
|
| 54 |
reaction_button = find("[data-reaction-button-id=\"reaction_message_#{reply_message.id}\"]")
|
|
| 55 |
assert_reaction_add_and_remove(reaction_button, reply_message) |
|
| 56 |
end |
|
| 57 |
end |
|
| 58 | ||
| 59 |
def test_react_to_forum_message |
|
| 60 |
log_user('jsmith', 'jsmith')
|
|
| 61 | ||
| 62 |
message = messages(:messages_001) |
|
| 63 | ||
| 64 |
with_settings(reactions_enabled: '1') do |
|
| 65 |
visit 'boards/1/topics/1' |
|
| 66 |
reaction_button = find("[data-reaction-button-id=\"reaction_message_#{message.id}\"]")
|
|
| 67 |
assert_reaction_add_and_remove(reaction_button, message) |
|
| 68 |
end |
|
| 69 |
end |
|
| 70 | ||
| 71 |
def test_react_to_news |
|
| 72 |
log_user('jsmith', 'jsmith')
|
|
| 73 | ||
| 74 |
with_settings(reactions_enabled: '1') do |
|
| 75 |
visit '/news/2' |
|
| 76 |
reaction_button = find("[data-reaction-button-id=\"reaction_news_2\"]")
|
|
| 77 |
assert_reaction_add_and_remove(reaction_button, news(:news_002)) |
|
| 78 |
end |
|
| 79 |
end |
|
| 80 | ||
| 81 |
def test_react_to_comment |
|
| 82 |
log_user('jsmith', 'jsmith')
|
|
| 83 | ||
| 84 |
comment = comments(:comments_002) |
|
| 85 | ||
| 86 |
with_settings(reactions_enabled: '1') do |
|
| 87 |
visit '/news/1' |
|
| 88 |
reaction_button = find("[data-reaction-button-id=\"reaction_comment_#{comment.id}\"]")
|
|
| 89 |
assert_reaction_add_and_remove(reaction_button, comment) |
|
| 90 |
end |
|
| 91 |
end |
|
| 92 | ||
| 93 |
def test_reactions_disabled |
|
| 94 |
log_user('jsmith', 'jsmith')
|
|