コード例 #1
0
def update_company(company_id, # pylint: disable=too-many-arguments
                   company_name=None,
                   company_manager_id=None,
                   username=None):
    """
    Updates an company and returns the newly updated company in dict format.
    A value of None means the field should not be updated.

    :param company_id: ID of the company to update.
    :type company_id: ID
    :param company_name: New company name.
    :type company_name: string | None
    :param company_manager_id: The ID of the company manager user.
    :type company_manager_id: string
    :return: dict representation of the company object.
    :rtype: dict
    """
    company = Company()
    try:
        company.load(str(company_id))
    except DoesNotExist as err:
        return {'errors': {'company_id': str(err)}}

    company_acl_verify(username, company)

    if company_name is not None:
        company.set_company_name(company_name)
    if company_manager_id is not None:
        val = hug.types.uuid(company_manager_id)
        company.set_company_manager_id(str(val))
    company.save()
    return company.to_dict()
コード例 #2
0
def create_company(auth_user: AuthUser,
                   company_name: str = None,
                   company_manager_id=None,
                   company_manager_user_name=None,
                   company_manager_user_email=None,
                   user_id=None,
                   response=None):
    """
    Creates an company and returns the newly created company in dict format.

    :param auth_user: The authenticated user
    :type auth_user: object
    :param company_name: The company name.
    :type company_name: string
    :param company_manager_id: The ID of the company manager user.
    :type company_manager_id: string
    :param company_manager_user_name: The user name of the company manager user.
    :type company_manager_user_name: string
    :param company_manager_user_email: The user email of the company manager user.
    :type company_manager_user_email: string
    :return: dict representation of the company object.
    :rtype: dict
    """
    fn = 'controllers.company.create_company'
    manager = cla.controllers.user.get_or_create_user(auth_user)

    for company in get_companies():
        if company.get("company_name") == company_name:
            cla.log.error({"error": "Company already exists"})
            response.status = HTTP_409
            return {"status_code": HTTP_409,
                    "data": {"error": "Company already exists.",
                             "company_id": company.get("company_id")}
                    }

    cla.log.debug(f'{fn} - creating company with name: {company_name}')
    company = Company()
    company.set_company_id(str(uuid.uuid4()))
    company.set_company_name(company_name)
    company.set_company_manager_id(manager.get_user_id())
    company.set_company_acl(manager.get_lf_username())
    company.save()
    cla.log.debug(f'{fn} - created company with name: {company_name} with company_id: {company.get_company_id()}')

    # Create audit trail for company
    event_data = f'User {auth_user.username} created Company {company.get_company_name()} ' \
                 f'with company_id: {company.get_company_id()}.'
    event_summary = f'User {auth_user.username} created Company {company.get_company_name()}.'
    Event.create_event(
        event_type=EventType.CreateCompany,
        event_company_id=company.get_company_id(),
        event_data=event_data,
        event_summary=event_summary,
        event_user_id=user_id,
        contains_pii=False,
    )

    return {"status_code": HTTP_200, "data": company.to_dict()}
コード例 #3
0
ファイル: company.py プロジェクト: prasannamahajan/easycla
def create_company(auth_user,
                   company_name=None,
                   company_manager_id=None,
                   company_manager_user_name=None,
                   company_manager_user_email=None,
                   user_id=None,
                   response=None):
    """
    Creates an company and returns the newly created company in dict format.

    :param company_name: The company name.
    :type company_name: string
    :param company_manager_id: The ID of the company manager user.
    :type company_manager_id: string
    :param company_manager_user_name: The user name of the company manager user.
    :type company_manager_user_name: string
    :param company_manager_user_email: The user email of the company manager user.
    :type company_manager_user_email: string
    :return: dict representation of the company object.
    :rtype: dict
    """

    manager = cla.controllers.user.get_or_create_user(auth_user)

    for company in get_companies():
        if company.get("company_name") == company_name:
            cla.log.error({"error": "Company already exists"})
            response.status = HTTP_409
            return {
                "status_code": HTTP_409,
                "data": {
                    "error": "Company already exists.",
                    "company_id": company.get("company_id")
                }
            }

    company = Company()
    company.set_company_id(str(uuid.uuid4()))
    company.set_company_name(company_name)
    company.set_company_manager_id(manager.get_user_id())
    company.set_company_acl(manager.get_lf_username())

    company.save()

    # Create audit trail for company
    event_data = 'Company-{} created'.format(company.get_company_name())
    Event.create_event(
        event_type=EventType.CreateCompany,
        event_company_id=company.get_company_id(),
        event_data=event_data,
        event_user_id=user_id,
        contains_pii=False,
    )

    return {"status_code": HTTP_200, "data": company.to_dict()}
コード例 #4
0
def update_company(
        company_id: str,  # pylint: disable=too-many-arguments
        company_name: str = None,
        company_manager_id: str = None,
        username: str = None):
    """
    Updates an company and returns the newly updated company in dict format.
    A value of None means the field should not be updated.

    :param company_id: ID of the company to update.
    :type company_id: str
    :param company_name: New company name.
    :type company_name: string | None
    :param company_manager_id: The ID of the company manager user.
    :type company_manager_id: str
    :param username: The username of the existing company manager user who performs the company update.
    :type username: str
    :return: dict representation of the company object.
    :rtype: dict
    """
    company = Company()
    try:
        company.load(str(company_id))
    except DoesNotExist as err:
        return {'errors': {'company_id': str(err)}}

    company_acl_verify(username, company)
    update_str = ""

    if company_name is not None:
        company.set_company_name(company_name)
        update_str += f"The company name was updated to {company_name}. "
    if company_manager_id is not None:
        val = hug.types.uuid(company_manager_id)
        company.set_company_manager_id(str(val))
        update_str += f"The company company manager id was updated to {val}"

    company.save()

    # Audit update event
    event_data = update_str
    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.UpdateCompany,
        event_company_id=company_id,
        contains_pii=False,
    )
    return company.to_dict()
コード例 #5
0
ファイル: company.py プロジェクト: zaclittleberry/easycla
def create_company(auth_user,
                   company_name=None,
                   company_manager_id=None,
                   company_manager_user_name=None,
                   company_manager_user_email=None,
                   user_id=None):
    """
    Creates an company and returns the newly created company in dict format.

    :param company_name: The company name.
    :type company_name: string
    :param company_manager_id: The ID of the company manager user.
    :type company_manager_id: string
    :param company_manager_user_name: The user name of the company manager user.
    :type company_manager_user_name: string
    :param company_manager_user_email: The user email of the company manager user.
    :type company_manager_user_email: string
    :return: dict representation of the company object.
    :rtype: dict
    """

    manager = cla.controllers.user.get_or_create_user(auth_user)

    for company in get_companies():
        if company.get("company_name") == company_name:
            cla.log.error({"error": "Company already exists"})
            return {
                "status_code": HTTP_409,
                "data": {
                    "error": "Company already exists.",
                    "company_id": company.get("company_id")
                }
            }

    company = Company()
    company.set_company_id(str(uuid.uuid4()))
    company.set_company_name(company_name)
    company.set_company_manager_id(manager.get_user_id())
    company.set_company_acl(manager.get_lf_username())

    company.save()

    return {"status_code": HTTP_200, "data": company.to_dict()}