|
10 | 10 |
|
11 | 11 | import os
|
12 | 12 | import re
|
13 |
| -import hashlib |
14 | 13 | from typing import List, Union, Optional
|
15 | 14 | from fastapi import (
|
16 | 15 | Depends,
|
@@ -317,17 +316,6 @@ async def authorize_user(node_id: str,
|
317 | 316 | return user
|
318 | 317 |
|
319 | 318 |
|
320 |
| -def calculate_submitter(hdr: str): |
321 |
| - """Calculate submitter hash from Auth header token""" |
322 |
| - token = hdr.split(' ')[1] |
323 |
| - if not token: |
324 |
| - raise HTTPException( |
325 |
| - status_code=status.HTTP_400_BAD_REQUEST, |
326 |
| - detail="Token not provided" |
327 |
| - ) |
328 |
| - return hashlib.md5(token.encode()).hexdigest() |
329 |
| - |
330 |
| - |
331 | 319 | @app.get('/users', response_model=PageModel, tags=["user"],
|
332 | 320 | response_model_exclude={"items": {"__all__": {
|
333 | 321 | "hashed_password"}}})
|
@@ -584,8 +572,9 @@ async def post_node(node: Node,
|
584 | 572 |
|
585 | 573 | await _verify_user_group_existence(node.user_groups)
|
586 | 574 | node.owner = current_user.username
|
587 |
| - # Subtract 'Bearer ' from the token |
588 |
| - node.submitter = calculate_submitter(authorization) |
| 575 | + # if node.submitter is not set, set it to "pipeline" |
| 576 | + if not node.submitter: |
| 577 | + node.submitter = "service:pipeline" |
589 | 578 |
|
590 | 579 | # The node is handled as a generic Node by the DB, regardless of its
|
591 | 580 | # specific kind. The concrete Node submodel (Kbuild, Checkout, etc.)
|
@@ -661,7 +650,15 @@ async def put_nodes(
|
661 | 650 | user: str = Depends(authorize_user)):
|
662 | 651 | """Add a hierarchy of nodes to an existing root node"""
|
663 | 652 | nodes.node.id = ObjectId(node_id)
|
664 |
| - submitter = calculate_submitter(authorization) |
| 653 | + # Retrieve the root node from the DB and submitter |
| 654 | + node_from_id = await db.find_by_id(Node, node_id) |
| 655 | + if not node_from_id: |
| 656 | + raise HTTPException( |
| 657 | + status_code=status.HTTP_404_NOT_FOUND, |
| 658 | + detail=f"Node not found with id: {node_id}" |
| 659 | + ) |
| 660 | + submitter = node_from_id.submitter |
| 661 | + |
665 | 662 | await _set_node_ownership_recursively(user, nodes, submitter)
|
666 | 663 | obj_list = await db.create_hierarchy(nodes, Node)
|
667 | 664 | data = _get_node_event_data('updated', obj_list[0], True)
|
|
0 commit comments