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 broken dashboard action logs under certain conditions #6857

Merged
merged 7 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def action_string
end
end

def has_diff?
action == "unpublish" || super
def diff_actions
super + %w(unpublish)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def changeset
).changeset
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Assemblies::AdminLog::AssembliesTypePresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { create(:assemblies_type, organization: organization) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Assemblies::AdminLog::AssemblyMemberPresenter, type: :helper do
include_examples "present admin log entry" do
let(:assembly) { create(:assembly, organization: organization) }
let(:admin_log_resource) { create(:assembly_member, assembly: assembly) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Assemblies::AdminLog::AssemblyPresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { create(:assembly, organization: organization) }
let(:action) { "unpublish" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Assemblies::AdminLog::AssemblyUserRolePresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { create(:assembly_user_role, user: user) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def action_string
end
end

def has_diff?
action == "unpublish" || super
def diff_actions
super + %w(unpublish)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def changeset
).changeset
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def action_string
end
end

def has_diff?
action == "delete" || super
def diff_actions
super + %w(delete)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::ConferencePresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { create(:conference, organization: organization) }
let(:action) { "unpublish" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::ConferenceRegistrationPresenter, type: :helper do
include_examples "present admin log entry" do
let(:conference) { create(:conference, organization: organization) }
let(:admin_log_resource) { create(:conference_registration, conference: conference) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::ConferenceSpeakerPresenter, type: :helper do
include_examples "present admin log entry" do
let(:conference) { create(:conference, organization: organization) }
let(:admin_log_resource) { create(:conference_speaker, conference: conference) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::ConferenceUserRolePresenter, type: :helper do
include_examples "present admin log entry" do
let(:conference) { create(:conference, organization: organization) }
let(:admin_log_resource) { create(:conference_user_role, conference: conference, user: user) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::MediaLinkPresenter, type: :helper do
include_examples "present admin log entry" do
let(:conference) { create(:conference, organization: organization) }
let(:admin_log_resource) { create(:media_link, conference: conference) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::PartnerPresenter, type: :helper do
include_examples "present admin log entry" do
let(:conference) { create(:conference, organization: organization) }
let(:admin_log_resource) { create(:partner, conference: conference) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Conferences::AdminLog::RegistrationTypePresenter, type: :helper do
include_examples "present admin log entry" do
let(:conference) { create(:conference, organization: organization) }
let(:admin_log_resource) { create(:registration_type, conference: conference) }
let(:action) { "delete" }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def action_string
end
end

def has_diff?
action == "unpublish" || super
def diff_actions
super + %w(unpublish)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def i18n_params
)
end

def has_diff?
action == "unreport" || super
def diff_actions
super + %w(unreport)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def i18n_labels_scope
"activemodel.attributes.organization"
end

def has_diff?
action == "update_id_documents_config" || super
def diff_actions
super + %w(update_id_documents_config)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def changeset
end

# If the action is officialization, then we want to show the diff
def has_diff?
%w(officialize unofficialize).include?(action)
def diff_actions
%w(officialize unofficialize)
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion decidim-core/app/presenters/decidim/log/base_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ def i18n_params
#
# Returns a Boolean.
def has_diff?
%w(update create).include?(action.to_s) && action_log.version.present?
diff_actions.include?(action.to_s) && action_log.version.present?
end

# Private: Lists the log actions for which the diff changeset should be
# shown.
#
# Returns a Boolean.
def diff_actions
%w(update create)
end

# Private: Calculates whether the diff should show the previous value
Expand Down
1 change: 1 addition & 0 deletions decidim-core/lib/decidim/core/test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "decidim/core/test/shared_examples/acts_as_author_examples"
require "decidim/core/test/shared_examples/admin_log_presenter_examples"
require "decidim/core/test/shared_examples/authorable"
require "decidim/core/test/shared_examples/coauthorable"
require "decidim/core/test/shared_examples/publicable"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "spec_helper"

shared_examples "present admin log entry" do
subject(:presenter) { described_class.new(action_log, helper) }

let(:organization) { create(:organization) }
let(:user) { create(:user, organization: organization) }
let(:action) { "create" }
let(:action_log) do
create(
:action_log,
user: user,
action: action,
resource: admin_log_resource
)
end

before do
helper.extend(Decidim::ApplicationHelper)
helper.extend(Decidim::TranslationsHelper)
end

describe "#present" do
subject { presenter.present }

context "when the logged action is one that shows diff and the action log does not have an associated version" do
it "returns an empty diff" do
expect(subject).not_to include("class=\"logs__log__diff\"")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::AdminLog::ComponentPresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { create(:component, organization: organization) }
let(:action) { "unpublish" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::AdminLog::ModerationPresenter, type: :helper do
include_examples "present admin log entry" do
let(:component) { create(:component, manifest_name: "dummy", organization: organization) }
let(:reportable) { create(:dummy_resource, component: component) }
let(:moderation) { create(:moderation, reportable: reportable) }
let(:admin_log_resource) { create(:report, moderation: moderation) }
let(:action) { "unreport" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::AdminLog::OrganizationPresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { organization }
let(:action) { "update_id_documents_config" }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::AdminLog::UserPresenter, type: :helper do
include_examples "present admin log entry" do
let(:admin_log_resource) { organization }
let(:action) { "officialize" }
end
end
Loading