-
Notifications
You must be signed in to change notification settings - Fork 3
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
LITE-28161 Add user id and name to Configuration events #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ class ConfigurationSchema(NonNullSchema): | |
id: str | ||
file: FileSchema | ||
state: ConfigurationStateChoices | ||
events: Dict[str, Dict[str, Union[datetime, str]]] | ||
events: Dict[str, Dict[str, Union[datetime, Dict[str, str]]]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the future --> TypeAliases will help you |
||
|
||
|
||
class ConfigurationReferenceSchema(NonNullSchema): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
) | ||
from connect.eaas.core.inject.synchronous import get_installation, get_installation_client | ||
from connect.eaas.core.extension import WebApplicationBase | ||
from fastapi import Depends, Response, status | ||
from fastapi import Depends, Request, Response, status | ||
from sqlalchemy import exists | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import joinedload | ||
|
@@ -44,6 +44,7 @@ | |
get_deployment_request_schema, | ||
get_deployment_schema, | ||
get_hubs, | ||
get_user_data_from_auth_token, | ||
) | ||
|
||
|
||
|
@@ -61,7 +62,7 @@ class ConnectExtensionXvsWebApplication(WebApplicationBase): | |
|
||
@router.get( | ||
'/deployments/requests', | ||
summary='List all request accross deployments', | ||
summary='List all requests across deployments', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just typos |
||
response_model=List[DeploymentRequestSchema], | ||
) | ||
def list_deployment_requests( | ||
|
@@ -220,6 +221,7 @@ def add_configuration( | |
deployment_id: str, | ||
db: VerboseBaseSession = Depends(get_db), | ||
installation: dict = Depends(get_installation), | ||
request: Request = None, | ||
): | ||
get_deployment_by_id(deployment_id, db, installation) | ||
file_data = configuration.file | ||
|
@@ -238,7 +240,7 @@ def add_configuration( | |
mime_type=file_data.mime_type, | ||
) | ||
db.add(file_instance) | ||
db.commit() | ||
db.flush() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed for transaction because db.commit() ends transaction |
||
|
||
prev_configuration = ( | ||
db.query(Configuration) | ||
|
@@ -251,10 +253,13 @@ def add_configuration( | |
if prev_configuration: | ||
prev_configuration.state = ConfigurationStateChoices.INACTIVE | ||
|
||
user_data = get_user_data_from_auth_token(request.headers['connect-auth']) | ||
configuration_instance = Configuration( | ||
file=file_data.id, | ||
deployment=deployment_id, | ||
state=ConfigurationStateChoices.ACTIVE, | ||
created_by=user_data, | ||
updated_by=user_data, | ||
) | ||
db.set_verbose(configuration_instance) | ||
db.commit() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,12 @@ def test_post_configuration( | |
'mime_type': media_response['mime_type'], | ||
}, | ||
}, | ||
headers={ | ||
"connect-auth": ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For tests it is better to generate the test signature based on human-readable input. Otherwise hard to understand what is inside and what should be expected in the tests |
||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1Ijp7Im9pZCI6IlNVLTI5NS02ODktN" | ||
"jI4IiwibmFtZSI6Ik5lcmkifX0.U_T6vuXnD293hcWNTJZ9QBViteNv8JXUL2gM0BezQ-k" | ||
), | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
data = response.json() | ||
|
@@ -123,8 +129,15 @@ def test_post_configuration( | |
'size': 17, | ||
'mime_type': 'application/json', | ||
} | ||
|
||
assert data['state'] == ConfigurationStateChoices.ACTIVE | ||
assert data['events']['created']['by'] == { | ||
'id': 'SU-295-689-628', | ||
'name': 'Neri', | ||
} | ||
assert data['events']['updated']['by'] == { | ||
'id': 'SU-295-689-628', | ||
'name': 'Neri', | ||
} | ||
|
||
assert dbsession.query(Configuration).count() == 1 | ||
assert dbsession.query(File).count() == 1 | ||
|
@@ -150,6 +163,12 @@ def test_post_configuration_deactivate_previous( | |
'mime_type': file.mime_type, | ||
}, | ||
}, | ||
headers={ | ||
"connect-auth": ( | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1Ijp7Im9pZCI6IlNVLTI5NS02ODktN" | ||
"jI4IiwibmFtZSI6Ik5lcmkifX0.U_T6vuXnD293hcWNTJZ9QBViteNv8JXUL2gM0BezQ-k" | ||
), | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly speaking, I don't like the idea of storing it as JSON here, cause of:
Let's have it as is for now, but I'll put it as the gap