mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
Add 'created_by' field to track project creator
This commit is contained in:
parent
1958deff09
commit
8ab34924b5
@ -113,6 +113,7 @@ async def get_projects(
|
||||
)
|
||||
async def create_project(
|
||||
project_data: schemas.ProjectCreate,
|
||||
current_user: schemas.User = Depends(get_current_active_user),
|
||||
) -> schemas.Project:
|
||||
"""
|
||||
Create a new project.
|
||||
@ -121,7 +122,10 @@ async def create_project(
|
||||
"""
|
||||
|
||||
controller = Controller.instance()
|
||||
project = await controller.add_project(**jsonable_encoder(project_data, exclude_unset=True))
|
||||
project_dict = jsonable_encoder(project_data, exclude_unset=True)
|
||||
if "created_by" not in project_dict:
|
||||
project_dict["created_by"] = current_user.username
|
||||
project = await controller.add_project(**project_dict)
|
||||
return project.asdict()
|
||||
|
||||
|
||||
|
||||
@ -97,6 +97,7 @@ class Project:
|
||||
show_interface_labels=False,
|
||||
variables=None,
|
||||
supplier=None,
|
||||
created_by=None,
|
||||
):
|
||||
|
||||
self._controller = controller
|
||||
@ -117,6 +118,7 @@ class Project:
|
||||
self._show_interface_labels = show_interface_labels
|
||||
self._variables = variables
|
||||
self._supplier = supplier
|
||||
self._created_by = created_by
|
||||
|
||||
self._loading = False
|
||||
self._closing = False
|
||||
@ -380,6 +382,21 @@ class Project:
|
||||
"""
|
||||
self._supplier = supplier
|
||||
|
||||
@property
|
||||
def created_by(self):
|
||||
"""
|
||||
Username of the user who created the project
|
||||
:return: str or None
|
||||
"""
|
||||
return self._created_by
|
||||
|
||||
@created_by.setter
|
||||
def created_by(self, created_by):
|
||||
"""
|
||||
Setter for the username of the user who created the project
|
||||
"""
|
||||
self._created_by = created_by
|
||||
|
||||
@property
|
||||
def auto_start(self):
|
||||
"""
|
||||
@ -1327,6 +1344,7 @@ class Project:
|
||||
"show_interface_labels": self._show_interface_labels,
|
||||
"supplier": self._supplier,
|
||||
"variables": self._variables,
|
||||
"created_by": self._created_by,
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@ -87,6 +87,7 @@ def project_to_topology(project):
|
||||
"show_interface_labels": project.show_interface_labels,
|
||||
"variables": project.variables,
|
||||
"supplier": project.supplier,
|
||||
"created_by": project.created_by,
|
||||
"topology": {"nodes": [], "links": [], "computes": [], "drawings": []},
|
||||
"type": "topology",
|
||||
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||
|
||||
@ -64,6 +64,7 @@ class ProjectBase(BaseModel):
|
||||
show_interface_labels: Optional[bool] = Field(None, description="Show interface labels on the drawing area")
|
||||
supplier: Optional[Supplier] = Field(None, description="Supplier of the project")
|
||||
variables: Optional[List[Variable]] = Field(None, description="Variables required to run the project")
|
||||
created_by: Optional[str] = Field(None, description="Username of the user who created the project")
|
||||
|
||||
|
||||
class ProjectCreate(ProjectBase):
|
||||
|
||||
@ -66,6 +66,7 @@ class Topology(BaseModel):
|
||||
show_interface_labels: Optional[bool] = Field(None, description="Show interface labels on the drawing area")
|
||||
supplier: Optional[Supplier] = Field(None, description="Supplier of the project")
|
||||
variables: Optional[List[Variable]] = Field(None, description="Variables required to run the project")
|
||||
created_by: Optional[str] = Field(None, description="Username of the user who created the project")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -81,10 +81,21 @@ async def test_json():
|
||||
"grid_size": 75,
|
||||
"drawing_grid_size": 25,
|
||||
"supplier": None,
|
||||
"variables": None
|
||||
"variables": None,
|
||||
"created_by": None
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_created_by():
|
||||
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
||||
p = Project(name="Test", created_by="admin")
|
||||
|
||||
assert p.created_by == "admin"
|
||||
assert p.asdict()["created_by"] == "admin"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update(controller):
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user