ome / omero-py

Python project containing Ice remoting code for OMERO
https://www.openmicroscopy.org/omero
GNU General Public License v2.0
20 stars 33 forks source link

How to set an owner for created project or dataset #422

Closed ArtemLogachov closed 1 month ago

ArtemLogachov commented 1 month ago

i have a functions:

def create_project(
    conn: BlitzGateway, project_name: str, project_description: str = ""
) -> int:
    """
    Creates a project on the OMERO server.

    Args:
        conn (BlitzGateway): The connection object to OMERO.
        project_name (str): The name of the project.
        project_description (str, optional): The description of the project. Defaults to "".

    Returns:
        int: The ID of the created project.
    """
    conn.keepAlive()
    project = ProjectI()
    project.name = rstring(project_name)
    project.description = rstring(project_description)
    update_service = conn.getUpdateService()
    project = update_service.saveAndReturnObject(project)
    return project.id.val

async def create_omero_project(
    username: str,
    password: str,
    project_name: str,
    project_description: str = "",
) -> int:
    try:
        conn = connect(system_config.OMERO_HOST, username, password)
    except Exception as e:
        logger.error(f"Failed to connect to OMERO server: {str(e)}")
        raise HTTPException(status_code=500, detail="Failed to connect to OMERO server")

    try:
        project_id = create_project(conn, project_name, project_description)
        return project_id
    except Exception as e:
        logger.error(f"Error creating project: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error creating project: {str(e)}")
    finally:
        conn.close()

create_omero_project is connecting to omero server with credentials we set and executes create_project

create_projects creates project and owner of this project will be the user whose credentials we used for the connection.

if we connect through a user with admin permissions, then do we have the opportunity to create a project with different owner (not user from which we connect)?

will-moore commented 1 month ago

You can set the project.details.owner = ExperimenterI( expId, False ) before saving the project. E.g. see https://github.com/ome/omero-web/blob/master/omeroweb/webclient/views.py#L1054

ArtemLogachov commented 1 month ago

thanks!