use our json encoder to dump the user for get_current_user script w/ burnettk
This commit is contained in:
parent
2c3b88042e
commit
5452b48d08
|
@ -1006,7 +1006,7 @@
|
|||
"emailVerified" : false,
|
||||
"email" : "kb@sartography.com",
|
||||
"attributes" : {
|
||||
"bamboo_id" : [ "42" ]
|
||||
"spiffworkflow-employeeid" : [ "42" ]
|
||||
},
|
||||
"credentials" : [ {
|
||||
"id" : "2c0be363-038f-48f1-86d6-91fdd28657cf",
|
||||
|
@ -2120,7 +2120,7 @@
|
|||
}
|
||||
}, {
|
||||
"id" : "a7692d41-b905-4049-9004-f6bea690051d",
|
||||
"name" : "bamboo_id",
|
||||
"name" : "spiffworkflow-employeeid",
|
||||
"protocol" : "openid-connect",
|
||||
"protocolMapper" : "oidc-usermodel-attribute-mapper",
|
||||
"consentRequired" : false,
|
||||
|
@ -2128,10 +2128,10 @@
|
|||
"aggregate.attrs" : "false",
|
||||
"userinfo.token.claim" : "true",
|
||||
"multivalued" : "false",
|
||||
"user.attribute" : "bamboo_id",
|
||||
"user.attribute" : "spiffworkflow-employeeid",
|
||||
"id.token.claim" : "true",
|
||||
"access.token.claim" : "true",
|
||||
"claim.name" : "bamboo_id"
|
||||
"claim.name" : "spiffworkflow-employeeid"
|
||||
}
|
||||
} ],
|
||||
"defaultClientScopes" : [ "web-origins", "acr", "profile", "roles", "email" ],
|
||||
|
@ -3652,4 +3652,4 @@
|
|||
"clientPolicies" : {
|
||||
"policies" : [ ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ class UserModel(SpiffworkflowBaseDBModel):
|
|||
service_id = db.Column(db.String(255), nullable=False, unique=False)
|
||||
display_name = db.Column(db.String(255))
|
||||
email = db.Column(db.String(255))
|
||||
tenant_specific_field_1 = db.Column(db.String(255))
|
||||
tenant_specific_field_2 = db.Column(db.String(255))
|
||||
tenant_specific_field_3 = db.Column(db.String(255))
|
||||
tenant_specific_field_1: str = db.Column(db.String(255))
|
||||
tenant_specific_field_2: str = db.Column(db.String(255))
|
||||
tenant_specific_field_3: str = db.Column(db.String(255))
|
||||
updated_at_in_seconds: int = db.Column(db.Integer)
|
||||
created_at_in_seconds: int = db.Column(db.Integer)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Get current user."""
|
||||
from typing import Any
|
||||
|
||||
from flask import current_app
|
||||
from flask import g
|
||||
|
||||
from spiffworkflow_backend.models.script_attributes_context import (
|
||||
|
@ -26,4 +27,7 @@ class GetCurrentUser(Script):
|
|||
**kwargs: Any
|
||||
) -> Any:
|
||||
"""Run."""
|
||||
return g.user.__dict__
|
||||
# dump the user using our json encoder and then load it back up as a dict
|
||||
# to remove unwanted field types
|
||||
user_as_json_string = current_app.json.dumps(g.user)
|
||||
return current_app.json.loads(user_as_json_string)
|
||||
|
|
|
@ -82,7 +82,8 @@
|
|||
<bpmn:incoming>Flow_0bgkfue</bpmn:incoming>
|
||||
<bpmn:outgoing>Flow_1ivhu7x</bpmn:outgoing>
|
||||
<bpmn:script>approver = get_current_user()
|
||||
lane_owners["Finance Team"].remove(approver)</bpmn:script>
|
||||
username = approver['username']
|
||||
lane_owners["Finance Team"].remove(username)</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
</bpmn:process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
"""Test_get_localtime."""
|
||||
from flask.app import Flask
|
||||
import json
|
||||
|
||||
from flask import g
|
||||
from flask.app import Flask
|
||||
from flask.testing import FlaskClient
|
||||
from spiffworkflow_backend.models.script_attributes_context import ScriptAttributesContext
|
||||
from spiffworkflow_backend.scripts.get_current_user import GetCurrentUser
|
||||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
|
||||
|
||||
from spiffworkflow_backend.models.db import db
|
||||
from spiffworkflow_backend.models.group import GroupModel
|
||||
from spiffworkflow_backend.models.user import UserModel
|
||||
from spiffworkflow_backend.services.process_instance_processor import (
|
||||
ProcessInstanceProcessor,
|
||||
from spiffworkflow_backend.models.script_attributes_context import (
|
||||
ScriptAttributesContext,
|
||||
)
|
||||
from spiffworkflow_backend.services.user_service import UserService
|
||||
from spiffworkflow_backend.models.user import UserModel
|
||||
from spiffworkflow_backend.scripts.get_current_user import GetCurrentUser
|
||||
|
||||
|
||||
class TestGetCurrentUser(BaseTest):
|
||||
|
||||
def test_get_current_user(
|
||||
self,
|
||||
app: Flask,
|
||||
|
@ -29,6 +26,9 @@ class TestGetCurrentUser(BaseTest):
|
|||
testuser1 = self.find_or_create_user("testuser1")
|
||||
testuser1.tenant_specific_field_1 = "456"
|
||||
db.session.add(testuser1)
|
||||
db.session.commit()
|
||||
|
||||
testuser1 = self.find_or_create_user("testuser1")
|
||||
g.user = testuser1
|
||||
process_model_identifier = "test_process_model"
|
||||
process_instance_id = 1
|
||||
|
@ -41,4 +41,6 @@ class TestGetCurrentUser(BaseTest):
|
|||
result = GetCurrentUser().run(
|
||||
script_attributes_context,
|
||||
)
|
||||
assert result['username'] == "testuser1"
|
||||
assert result["username"] == "testuser1"
|
||||
assert result["tenant_specific_field_1"] == "456"
|
||||
json.dumps(result)
|
||||
|
|
Loading…
Reference in New Issue