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

Do not show the service to the user if it is disabled, fixes #6184 #8406

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/helpers/publisher_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# the COPYRIGHT file.

module PublisherHelper
def available_services
current_user.services.select {|service| AppConfig.configured_services.map(&:to_s).include? service.provider }
end

def service_button(service)
provider_title = I18n.t("services.index.share_to", provider: service.provider.titleize)
content_tag :div,
Expand Down
6 changes: 3 additions & 3 deletions app/views/publisher/_publisher.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
%button.btn.btn-group.btn-primary#submit= t("shared.publisher.share")

.btn-toolbar.pull-right#publisher-service-icons
- if current_user.services
- current_user.services.each do |service|
= service_button(service)
- available_services.each do |service|
= service_button(service)

.btn.btn-link.question_mark{title: t("shared.public_explain.manage"),
data: {toggle: "modal", target: "#publicExplainModal"}}
%i.entypo-cog
Expand Down
9 changes: 4 additions & 5 deletions app/views/publisher/_publisher.mobile.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
= hidden_field_tag "aspect_ids[]", "all_aspects"
.form-group
%span#publisher-service-icons
- if current_user.services
- for service in current_user.services
= image_tag "social-media-logos/#{service.provider}-32x32.png",
title: service.provider.titleize, class: "service_icon dim",
id: "#{service.provider}", maxchar: "#{service.class::MAX_CHARACTERS}"
- available_services.each do |service|
= image_tag "social-media-logos/#{service.provider}-32x32.png",
title: service.provider.titleize, class: "service_icon dim",
id: service.provider, maxchar: service.class::MAX_CHARACTERS.to_s

.clear
#publisher-textarea-wrapper
Expand Down
4 changes: 4 additions & 0 deletions config/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,9 @@ test:
enable: true
key: 'fake'
secret: 'sdoigjosdfijg'
tumblr:
enable: true
key: 'fake'
secret: 'sdoigjosdfijg'
mail:
enable: true
19 changes: 19 additions & 0 deletions spec/helpers/publisher_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# frozen_string_literal: true

describe PublisherHelper, type: :helper do
describe "#available_services" do
include Devise::Test::ControllerHelpers

before do
@user = alice

@user.services << FactoryBot.build(:service, type: "Services::Wordpress", provider: "wordpress")
@user.services << FactoryBot.build(:service, type: "Services::Tumblr", provider: "tumblr")

def current_user
@user
end
end

it "returns only the connected and enabled services" do
expect(available_services.map(&:provider)).to eq(%w[tumblr])
end
end

describe "#public_selected?" do
it "returns true when the selected_aspects contains 'public'" do
expect(helper.public_selected?(["public"])).to be_truthy
Expand Down