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

Space add "Website Settings" section and enforce ssl checkbox #1484

Merged
merged 18 commits into from
May 25, 2023

Conversation

KellyAH
Copy link
Contributor

@KellyAH KellyAH commented May 20, 2023


Changes

  • Add "Website Settings" section
  • Add enforce ssl checkbox to Spaces edit page
  • only space members can see the new "Website Settings" section.
  • Update space policy with :enforce_ssl permitted param
  • add logic update the spaces table enforce_ssl with the checkbox value boolean (dependent on to ✨ 🥔 🥗 Spaces add Enforce_SSL flag #1479)
  • add unit tests
Screenshot 2023-05-24 at 5 51 16 PM

@KellyAH
Copy link
Contributor Author

KellyAH commented May 20, 2023

Test Cases to test on Local

  • If a user checks the Enforce SSL checkbox on /spaces/<space-name>/edit, and then clicks the Save changes button, the checkbox stays checked and the DB space table enforce_ssl value is true
  • If a user unchecks the Enforce SSL checkbox on /spaces/<space-name>/edit, and then clicks the Save changes button, the checkbox stays unchecked and the DB space table enforce_ssl value is false
  • Refresh/force refresh /spaces/<space-name>/edit preserves the Enforce SSL checkbox state.

@KellyAH
Copy link
Contributor Author

KellyAH commented May 20, 2023

@zspencer I forgot to ask you where on the /spaces/<space-name>/edit page do you want the Enforce SSL checkbox to be added? Utilities Section a different section, or a new Security section?

@anaulin
Copy link
Member

anaulin commented May 20, 2023

It feels like we're starting to need a new "general space settings" section. (With maybe a better / more concise title, probably.)

@zspencer
Copy link
Member

For now an "Operator Only Settings" section feels like maybe the right place; that way we could also expose the branded_domain field there

Copy link
Member

@zspencer zspencer left a comment

Choose a reason for hiding this comment

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

This is a great direction! Hopefully the comments I left were useful!

app/controllers/invitations_controller.rb Outdated Show resolved Hide resolved
app/views/spaces/_utilities.html.erb Outdated Show resolved Hide resolved
@KellyAH
Copy link
Contributor Author

KellyAH commented May 21, 2023

Will continue on sunday 5/21

@KellyAH KellyAH self-assigned this May 22, 2023
@KellyAH
Copy link
Contributor Author

KellyAH commented May 22, 2023

@zspencer should I add browser tests or any unit tests for the new "Operator Only Settings" section? Or is it too early

@KellyAH KellyAH marked this pull request as ready for review May 22, 2023 04:38
@KellyAH KellyAH changed the title Space add enforce ssl checkbox Space add "Operator Only Settings" section and enforce ssl checkbox May 22, 2023
@KellyAH KellyAH added the ✨ feature Reduces Client's Burden or Grants them Benefits label May 22, 2023
@KellyAH KellyAH changed the title Space add "Operator Only Settings" section and enforce ssl checkbox Space add "Operator Only Settings" section and enforce ssl checkbox May 22, 2023
@zspencer
Copy link
Member

It would be good to have a spec/requests/spaces_controller_request_spec#update test to make sure that the enable_ssl flag gets set to true when the form comes through; but I think a full system test would be too much since we're probably going to move this around soon anyway.

Copy link
Member

@zspencer zspencer left a comment

Choose a reason for hiding this comment

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

So long as you have confirmed that the data flips when the form submits I am comfortable with you merging this.

@zspencer
Copy link
Member

Maybe this is actually "Website Settings" and not "Operator Only Settings" 🙃

@KellyAH KellyAH marked this pull request as draft May 23, 2023 04:27
@KellyAH KellyAH changed the title Space add "Operator Only Settings" section and enforce ssl checkbox Space add "Website Settings" section and enforce ssl checkbox May 23, 2023
@KellyAH
Copy link
Contributor Author

KellyAH commented May 23, 2023

Maybe this is actually "Website Settings" and not "Operator Only Settings" 🙃

Renamed to "Website Settings" in the code and UI in 5910f5c

elsif params[:enforce_ssl] == 1
policy_scope(Space).friendly.find(params[:id]).update(enforce_ssl: true)
elsif params[:enforce_ssl] == 0
policy_scope(Space).friendly.find(params[:id]).update(enforce_ssl: false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is the correct way to update Space record based on the checkbox value.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this does seem a little off-the-rails to me. Normally, if space_params includes enforce_ssl it will update just fine from the browser without needing to do a comparison check; so you shouldn't have to change the controller since you're permitting the new param in the SpacePolicy.

new_entrance = space.rooms.sample
put polymorphic_path(space), params: {space: {entrance_id: new_entrance.id, enforce_ssl: 0}}

expect(space.enforce_ssl).to be false
Copy link
Contributor Author

@KellyAH KellyAH May 24, 2023

Choose a reason for hiding this comment

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

Tests still fail. IDK why.

I see the Space record updating enforce_ssl to the correct value in Puma logs when submitting the form on local.

Copy link
Member

Choose a reason for hiding this comment

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

Both the Controller space instance and the spec space instance have the same id (since they're referencing the same piece of data where it's stored in the database) but will have a different location in memory; so changes to the space instance in the Controller will only be reflected in space instance in the spec once the space instance in the spec re-queries the database to get the updated value.

TL/DR: You may want to call space.reload after executing the put because the computer caches the data in the Space record independently between the Controller and spec until it is re-queried..

Copy link
Member

@zspencer zspencer left a comment

Choose a reason for hiding this comment

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

I think this is good progress; and would be happy to merge it once the tests pass. That said; there are a couple ways to bring this closer to "Rails-normal":

  1. Revert the changes in SpacesController
  2. Use true and false in your spaces_controller_request_spec

elsif params[:enforce_ssl] == 1
policy_scope(Space).friendly.find(params[:id]).update(enforce_ssl: true)
elsif params[:enforce_ssl] == 0
policy_scope(Space).friendly.find(params[:id]).update(enforce_ssl: false)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this does seem a little off-the-rails to me. Normally, if space_params includes enforce_ssl it will update just fine from the browser without needing to do a comparison check; so you shouldn't have to change the controller since you're permitting the new param in the SpacePolicy.

<%= web_settings_form.check_box :enforce_ssl %>
Enforce SSL - Automatically redirects all Visitor traffic to this Space to https.
<% end %>
<%= web_settings_form.submit %>
Copy link
Member

Choose a reason for hiding this comment

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

Nice

new_entrance = space.rooms.sample
put polymorphic_path(space), params: {space: {entrance_id: new_entrance.id, enforce_ssl: 0}}

expect(space.enforce_ssl).to be false
Copy link
Member

Choose a reason for hiding this comment

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

Both the Controller space instance and the spec space instance have the same id (since they're referencing the same piece of data where it's stored in the database) but will have a different location in memory; so changes to the space instance in the Controller will only be reflected in space instance in the spec once the space instance in the spec re-queries the database to get the updated value.

TL/DR: You may want to call space.reload after executing the put because the computer caches the data in the Space record independently between the Controller and spec until it is re-queried..


it "enables Enforce SSL on a Space" do
new_entrance = space.rooms.sample
put polymorphic_path(space), params: {space: {entrance_id: new_entrance.id, enforce_ssl: 1}}
Copy link
Member

Choose a reason for hiding this comment

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

You can use false and true in your params (and it is generally preferred)

KellyAH and others added 2 commits May 24, 2023 17:51
and fix unit tests.

Co-authored-by: Zee Spencer <zspencer@users.noreply.github.com>
Co-authored-by: Ana <anaulin@users.noreply.github.com>
Co-authored-by: Dalton Pruitt <daltonrpruitt@users.noreply.github.com>
@KellyAH KellyAH marked this pull request as ready for review May 25, 2023 00:54
@KellyAH KellyAH merged commit 66b9fbf into main May 25, 2023
@KellyAH KellyAH deleted the 1473-add-Enforce-SSL-checkbox branch May 25, 2023 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature Reduces Client's Burden or Grants them Benefits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants