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

Sharing messaging #481

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Sharing messaging #481

wants to merge 12 commits into from

Conversation

kildre
Copy link
Contributor

@kildre kildre commented Sep 16, 2024

This PR handle error handling and messaging. When a user with a shared app tries to start/stop an app they will get a message alerting them they don't have permission to perform that action.

Reference Issues or PRs

What does this implement/fix?

Fixes the issues of a user wondering why they can't perform an action, now it give them an issue.
Put a x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds a feature)
  • Breaking change (fix or feature that would cause existing features not to work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Other (please describe):

Testing

  • Did you test the pull request locally?
  • Did you add new tests?

Documentation

Access-centered content checklist

Text styling

  • The content is written with plain language (where relevant).
  • If there are headers, they use the proper header tags (with only one level-one header: H1 or # in markdown).
  • All links describe where they link to (for example, check the Nebari website).
  • This content adheres to the Nebari style guides.

Non-text content

  • All content is represented as text (for example, images need alt text, and videos need captions or descriptive transcripts).
  • If there are emojis, there are not more than three in a row.
  • Don't use flashing GIFs or videos.
  • If the content were to be read as plain text, it still makes sense, and no information is missing.

Any other comments?

image
image
image

Copy link

vercel bot commented Sep 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jhub-apps ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2024 5:57pm
jhub-apps-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2024 5:57pm

Copy link
Collaborator

@jbouder jbouder left a comment

Choose a reason for hiding this comment

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

Should all of these API tests be commented out and/or removed like this?

Copy link
Collaborator

@jbouder jbouder left a comment

Choose a reason for hiding this comment

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

It doesn't look like you're handling the situation where a user clicks the card for a stopped app that is shared. Right now, clicking the app, then clicking the Modal Start button, you see a success message, then the screen refreshes.

Copy link
Collaborator

@jbouder jbouder left a comment

Choose a reason for hiding this comment

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

Looking really good! 1 potential thing to fix.

ui/src/components/app-card/app-card.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@jbouder jbouder left a comment

Choose a reason for hiding this comment

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

Great work!

Comment on lines 173 to 186
shared_servers = get_shared_servers(current_hub_user=user)
if server_name and any(server['name'] == server_name for server in shared_servers):
# User is trying to start a shared server without permission
raise HTTPException(
detail=f"User '{user.name}' does not have permission to start server '{server_name}'",
status_code=status.HTTP_403_FORBIDDEN,
)
except ValueError as e:
logger.error(f"Error in shared servers check: {e}")
raise HTTPException(
detail=f"Failed to check shared servers: {e}",
status_code=status.HTTP_400_BAD_REQUEST,
)

Copy link
Member

Choose a reason for hiding this comment

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

This permissions part needs to be handled on JupyterHub side (as JupyterHub knows what permissions a user have and jhub-apps service doesn't), jhub-apps service is not responsible for this and besides the checks done here is not sufficient to determine if the user has permissions to start the server or not. We actually just need to call hub_client.start_server and based on the response to it, we need to return appropriate response.

Comment on lines 83 to 85
assert response.json() == create_server_response


@patch.object(HubClient, "start_server")
def test_api_start_server(create_server, client):
start_server_response = {"user": "jovyan"}
create_server.return_value = start_server_response
server_name = "server-name"
response = client.post(
f"/server/{server_name}",
)
create_server.assert_called_once_with(
username=MOCK_USER.name,
servername=server_name,
)
assert response.status_code == 200
assert response.json() == start_server_response


@patch.object(HubClient, "start_server")
def test_api_start_server_404(start_server, client):
start_server_response = None
start_server.return_value = start_server_response
server_name = "server-name"
response = client.post(
f"/server/{server_name}",
)
start_server.assert_called_once_with(
username=MOCK_USER.name,
servername=server_name,
)
assert response.status_code == 404
assert response.json() == {"detail": "server 'server-name' not found"}

assert response.json() == create_server_response

Copy link
Member

Choose a reason for hiding this comment

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

We'd need to undo removal of these tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants