Exemple #1
0
def add_permission(auth_user: AuthUser,
                   username: str,
                   company_id: str,
                   ignore_auth_user=False):
    if not ignore_auth_user and auth_user.username not in admin_list:
        return {'error': 'unauthorized'}

    cla.log.info('company ({}) added for user ({}) by {}'.format(
        company_id, username, auth_user.username))

    company = Company()
    try:
        company.load(company_id)
    except Exception as err:
        print('Unable to update company permission: {}'.format(err))
        return {'error': str(err)}

    company.add_company_acl(username)
    event_data = f'Permissions added to user {username} for Company {company.get_company_name()}'
    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.AddCompanyPermission,
        event_company_id=company_id,
        contains_pii=True,
    )
    company.save()
Exemple #2
0
def add_permission(auth_user: AuthUser,
                   username: str,
                   company_id: str,
                   ignore_auth_user=False):
    fn = 'controllers.company.add_permission'
    if not ignore_auth_user and auth_user.username not in admin_list:
        return {'error': 'unauthorized'}

    cla.log.info(
        f'{fn} - company ({company_id}) added for user ({username}) by {auth_user.username}'
    )

    company = Company()
    try:
        company.load(company_id)
    except Exception as err:
        cla.log.warning(f'{fn} - unable to update company permission: {err}')
        return {'error': str(err)}

    company.add_company_acl(username)
    event_data = f'Added to user {username} to Company {company.get_company_name()} permissions list.'
    Event.create_event(
        event_data=event_data,
        event_summary=event_data,
        event_type=EventType.AddCompanyPermission,
        event_company_id=company_id,
        contains_pii=True,
    )
    company.save()
Exemple #3
0
def add_permission(auth_user: AuthUser, username: str, company_id: str, ignore_auth_user=False):
    if not ignore_auth_user and auth_user.username not in admin_list:
        return {'error': 'unauthorized'}

    cla.log.info('company ({}) added for user ({}) by {}'.format(company_id, username, auth_user.username))

    company = Company()
    try:
        company.load(company_id)
    except Exception as err:
        print('Unable to update company permission: {}'.format(err))
        return {'error': str(err)}

    company.add_company_acl(username)
    company.save()
Exemple #4
0
def invite_cla_manager(contributor_id, contributor_name, contributor_email,
                       cla_manager_name, cla_manager_email, project_name,
                       company_name):
    """
    Sends email to the specified CLA Manager to sign up through the Corporate
    console and adds the requested user to the Approved List request queue.

    :param contributor_id: The id of the user inviting the CLA Manager
    :param contributor_name: The name of the user inviting the CLA Manager
    :param contributor_email: The email address that this user wants to be added to the Approved List. Must exist in the user's list of emails.
    :param cla_manager_name: The name of the CLA manager
    :param cla_manager_email: The email address of the CLA manager
    :param project_name: The name of the project
    :param company_name: The name of the organization/company
    """
    user = User()
    try:
        user.load(contributor_id)
    except DoesNotExist as err:
        msg = f'unable to load user by id: {contributor_id} for inviting company admin - error: {err}'
        cla.log.warning(msg)
        return {
            'errors': {
                'user_id': contributor_id,
                'message': msg,
                'error': str(err)
            }
        }

    project = Project()
    try:
        project.load_project_by_name(project_name)
    except DoesNotExist as err:
        msg = f'unable to load project by name: {project_name} for inviting company admin - error: {err}'
        cla.log.warning(msg)
        return {
            'errors': {
                'project_name': project_name,
                'message': msg,
                'error': str(err)
            }
        }
    company = Company()
    try:
        company.load_company_by_name(company_name)
    except DoesNotExist as err:
        msg = f'unable to load company by name: {company_name} - error: {err}'
        cla.log.warning(msg)
        company.set_company_id(str(uuid.uuid4()))
        company.set_company_name(company_name)
        company.save()

    # Add user lfusername if exists
    username = None
    if user.get_lf_username():
        username = user.get_lf_username()
    elif user.get_user_name():
        username = user.get_user_name()
    if username:
        company.add_company_acl(username)
        company.save()

    # create company invite
    company_invite = CompanyInvite()
    company_invite.set_company_invite_id(str(uuid.uuid4()))
    company_invite.set_requested_company_id(company.get_company_id())
    company_invite.set_user_id(user.get_user_id())
    company_invite.save()

    # We'll use the user's provided contributor name - if not provided use what we have in the DB
    if contributor_name is None:
        contributor_name = user.get_user_name()

    log_msg = (
        f'sent email to CLA Manager: {cla_manager_name} with email {cla_manager_email} '
        f'for project {project_name} and company {company_name} '
        f'to user {contributor_name} with email {contributor_email}')
    # Send email to the admin. set account_exists=False since the admin needs to sign up through the Corporate Console.
    cla.log.info(log_msg)
    send_email_to_cla_manager(project, contributor_name, contributor_email,
                              cla_manager_name, cla_manager_email,
                              company_name, False)

    # update ccla_whitelist_request
    ccla_whitelist_request = CCLAWhitelistRequest()
    ccla_whitelist_request.set_request_id(str(uuid.uuid4()))
    ccla_whitelist_request.set_company_name(company_name)
    ccla_whitelist_request.set_project_name(project_name)
    ccla_whitelist_request.set_user_github_id(contributor_id)
    ccla_whitelist_request.set_user_github_username(contributor_name)
    ccla_whitelist_request.set_user_emails(set([contributor_email]))
    ccla_whitelist_request.set_request_status("pending")
    ccla_whitelist_request.save()

    Event.create_event(
        event_user_id=contributor_id,
        event_project_name=project_name,
        event_data=log_msg,
        event_summary=log_msg,
        event_type=EventType.InviteAdmin,
        contains_pii=True,
    )