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

Conversation

Flaburgan
Copy link
Member

@Flaburgan Flaburgan commented Oct 31, 2022

I was wondering if we should disconnect all users if we detect that the podmin changed the config to disable the service, but first of all config change isn't easy to detect, and second I think that if the podmin then re-enables it it would be a shame to ask all users to reconnect.

@denschub
Copy link
Member

This breaks Jasmine, there are specs that have expectations around available services that are no longer true with this PR.

Copy link
Member

@denschub denschub left a comment

Choose a reason for hiding this comment

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

(see previous comment)

@Flaburgan
Copy link
Member Author

Yep, it should be fixed now. I had to switch to another computer so it took time for diaspora-dev setup to run.
Should I also add a test to test the code I wrote? Should it be rspec or cucumber?

@Flaburgan
Copy link
Member Author

OK so I'm confused @SuperTux88 said this to me on IRC:

the jasmine spec is probably broken because it generates the templates with different settings ... the change you made in publisher_view_spec.js doesn't affect _publisher.html.haml so you need to change the configured services in the rspec test that generates the template that is used for the failing jasmine test ... and to test that locally you need to re-generate the fixtures locally, because you probably still have them from before your change

But actually locally the jasmine tests are green without adding anything else that what I did here. What you are saying is that I should also modify publisher_spec.rb?

@SuperTux88
Copy link
Member

But actually locally the jasmine tests are green without adding anything else that what I did here. What you are saying is that I should also modify publisher_spec.rb?

When I wrote that I didn't check which fixture is used and where it's generated. I assumed that you didn't re-generate your fixtures locally, so you are still using fixtures that were generated before your change in _publisher.html.haml. And the change you did to publisher_view_spec.js isn't needed and doesn't change anything, as it doesn't affect the fixture (locally your tests are probably green with or without that change there? But if you re-generate fixtures with bin/rake tests:generate_fixtures, then I assume that your tests aren't green anymore).

So in the line below the line you added, you see it loads aspects_index_services, and that one is generated in aspects_spec.rb, so you need to change that so the fixture still contains the services, and then jasmine will work again.

@Flaburgan
Copy link
Member Author

The related tests are fixed, the current failure in Rspec is unrelated, develop is also failing on that test. So this should be ready for review.

@Flaburgan Flaburgan force-pushed the 6184-service-disabled branch 2 times, most recently from cdac600 to b3b2a16 Compare February 7, 2023 22:47
Copy link
Member

@denschub denschub left a comment

Choose a reason for hiding this comment

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

Ideally, this would have a test with a service that's disabled globally but enabled in the user settings, and then confirming that the button isn't showing up. Writing a test for the actual behavior change here, that is.

But I feel adventurous today, so I'm personally not gonna block on that.

@@ -57,7 +57,8 @@
.btn-toolbar.pull-right#publisher-service-icons
- if current_user.services
- current_user.services.each do |service|
= service_button(service)
- if AppConfig.configured_services.map(&:to_s).include? service.provider
Copy link
Member

Choose a reason for hiding this comment

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

This only fixes it for the standard (desktop) UI, but it would also need to be fixed on mobile. And then it probably would be better to just extract a little helper to publisher_helper.rb that returns a list of all enabled services, which can then be looped over for both UIs (without needing to do additional filters), and is also easier to write a little test for.

@@ -57,7 +57,8 @@
.btn-toolbar.pull-right#publisher-service-icons
- if current_user.services
Copy link
Member

Choose a reason for hiding this comment

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

Sidenote, as you didn't change it here, but I don't think this if is needed, as if there are no services, the list would just be empty, so there is nothing to loop over anyway?

@Flaburgan
Copy link
Member Author

So I created a helper as suggested and used it in both version, the HTML of the desktop app works fine in the mobile app.
However, it is hard to test as I can't enable services for my user locally (if you can tell me how to do that).

If I copy paste the expected HTML, the design looks good:
Capture d’écran 2024-02-11 à 18 04 21

But the current helper code doesn't work apparently, it returns an empty array [] straight into the view:

Capture d’écran 2024-02-11 à 18 02 55

Could you explain me why?

Copy link
Member

@SuperTux88 SuperTux88 left a comment

Choose a reason for hiding this comment

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

However, it is hard to test as I can't enable services for my user locally (if you can tell me how to do that).

Just create a dummy service with dummy data on the user manually. You won't be able to post to it, but you can test if the buttons show:

user = User.find_by(username: "test")
user.services << Services::Tumblr.new(nickname: "nick", access_token: "token", access_secret: "secret", uid: "uid", provider: "Tumblr")
user.services << Services::Wordpress.new(nickname: "nick", access_token: "token", access_secret: "secret", uid: "uid", provider: "Wordpress")

Comment on lines 9 to 11
current_user.services.each do |service|
return service_button(service) if AppConfig.configured_services.map(&:to_s).include? service.provider
end
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain me why?

Because doing an each with a return doesn't work. If current_user.services is empty, it will just return the empty array, as the inner return will never trigger. Also if the if inside the loop is never true (if none of the connected services are actually enabled) it will just return the current_user.services to the view:

image

What I meant with a helper-method was just a method that filters the current_user.services with the enabled services, but doesn't try to render any buttons.

@@ -32,3 +26,5 @@
data: {"disable-with" => t("shared.publisher.posting")}
.pull-right
= render partial: "aspects/aspect_dropdown"
.pull-right#publisher-service-icons
= display_available_services
Copy link
Member

@SuperTux88 SuperTux88 Jun 2, 2024

Choose a reason for hiding this comment

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

I see what you tried to do here, but service_button(service) (which you tried to return in display_available_services) doesn't work on mobile, as the wordpress icon isn't available there in this form.

Lets just keep this the way it was before, but just change the source of the for loop to the filtered service list from the helper.

If you want to redesign how this looks on the mobile UI, this requires more work (there were also broken tests because of the UI changes), but I think it's not worth it, since the mobile UI will die eventually anyway.

@SuperTux88
Copy link
Member

I removed your last commit, and added my own with the helper that just filters the services and also added a test for that helper.

This now just filters the services for both UIs (so fixes the bug for both of them), but keeps the design otherwise as is.

@SuperTux88 SuperTux88 requested a review from denschub June 2, 2024 03:12
@Flaburgan
Copy link
Member Author

Thank you for finishing this

@SuperTux88 SuperTux88 merged commit c3eaa21 into diaspora:develop Jun 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants