Esempio n. 1
0
def update_openrecords_user(form):
    """
    Update OpenRecords-specific user attributes.
    :param form: validated ManageUserAccountForm or ManageAgencyUserAccountForm
    :type form: app.auth.forms.ManageUserAccountForm or app.auth.forms.ManageAgencyUserAccountForm
    """
    update_object(
        {
            'title':
            form.title.data,
            'organization':
            form.organization.data,
            'notification_email':
            form.notification_email.data,
            'phone_number':
            form.phone_number.data,
            'fax_number':
            form.fax_number.data,
            'mailing_address':
            create_mailing_address(form.address_one.data or None,
                                   form.city.data or None, form.state.data
                                   or None, form.zipcode.data or None,
                                   form.address_two.data or None)
        }, Users, (current_user.guid, current_user.auth_user_type))

    if current_user.is_agency and current_user.default_agency_ein != form.default_agency.data:
        update_object({'is_primary_agency': False}, AgencyUsers,
                      (current_user.guid, current_user.auth_user_type,
                       current_user.default_agency_ein))
        update_object({'is_primary_agency': True}, AgencyUsers,
                      (current_user.guid, current_user.auth_user_type,
                       form.default_agency.data))
Esempio n. 2
0
 def mailing_address(self):
     return create_mailing_address(
         fake.street_address(),
         fake.city(),
         fake.state_abbr(),
         fake.zipcode(),
     )
Esempio n. 3
0
def get_address(form):
    """
    Get mailing address from form data.

    :type form: app.request.forms.AgencyUserRequestForm
                app.request.forms.AnonymousRequestForm
    """
    return create_mailing_address(form.address.data or None, form.city.data
                                  or None, form.state.data or None,
                                  form.zipcode.data or None,
                                  form.address_two.data or None)
Esempio n. 4
0
def get_address(form):
    """
    Get mailing address from form data.

    :type form: app.request.forms.AgencyUserRequestForm
                app.request.forms.AnonymousRequestForm
    """
    return create_mailing_address(
        form.address.data or None,
        form.city.data or None,
        form.state.data or None,
        form.zipcode.data or None,
        form.address_two.data or None
    )
Esempio n. 5
0
def create_user(
    first_name=None,
    last_name=None,
    email=None,
    ein=None,
    is_admin=False,
    is_active=False,
):
    """Create an agency user."""
    if first_name is None:
        raise InvalidCommand("First name is required")

    if last_name is None:
        raise InvalidCommand("Last name is required")

    if email is None:
        raise InvalidCommand("Email is required")

    if ein is None:
        raise InvalidCommand("Agency EIN is required")

    user = Users(
        guid=generate_guid(),
        auth_user_type=user_type_auth.AGENCY_LDAP_USER,
        email=email,
        first_name=first_name,
        last_name=last_name,
        title=None,
        organization=None,
        email_validated=True,
        terms_of_use_accepted=True,
        phone_number=None,
        fax_number=None,
        mailing_address=create_mailing_address(None, None, None, None),
    )
    db.session.add(user)

    agency_user = AgencyUsers(
        user_guid=user.guid,
        auth_user_type=user.auth_user_type,
        agency_ein=ein,
        is_agency_active=is_active,
        is_agency_admin=is_admin,
        is_primary_agency=True,
    )
    db.session.add(agency_user)
    db.session.commit()

    print(user)
Esempio n. 6
0
def update_openrecords_user(form):
    """
    Update OpenRecords-specific user attributes.

    Args:
        form (app.auth.forms.ManageAgencyUserAccountForm OR app.auth.forms.ManageUserAccountForm): validated form
    """
    update_object(
        {
            'title': form.title.data,
            'organization': form.organization.data,
            'notification_email': form.notification_email.data,
            'phone_number': form.phone_number.data,
            'fax_number': form.fax_number.data,
            '_mailing_address': create_mailing_address(
                form.address_one.data or None,
                form.city.data or None,
                form.state.data or None,
                form.zipcode.data or None,
                form.address_two.data or None)
        },
        Users,
        current_user.guid
    )

    if current_user.is_agency and current_user.default_agency_ein != form.default_agency.data:
        update_object(
            {'is_primary_agency': False},
            AgencyUsers,
            (current_user.guid, current_user.default_agency_ein)
        )
        update_object(
            {'is_primary_agency': True},
            AgencyUsers,
            (current_user.guid, form.default_agency.data)
        )
def transfer_users(user_ids_to_guids, user):
    """
    Agency users are determined by the presence of a department_id, otherwise
    a user is stored as anonymous.
    A user's first and last name and middle initial are parsed from `alias`.

    :param user_ids_to_guids: empty dictionary that will be populated

    """
    # get agency_ein and auth_user_type
    auth_user_type = user_type_auth.AGENCY_LDAP_USER
    is_active = False
    if user.department_id:
        CUR_V1.execute("SELECT name FROM department WHERE id = %s" % user.department_id)
        agency_ein = AGENCY_V1_NAME_TO_EIN[CUR_V1.fetchone().name]
        is_active = True
    else:
        agency_ein = None
        auth_user_type = user_type_auth.ANONYMOUS_USER

    mailing_address = create_mailing_address(
        user.address1,
        user.city,
        user.state,
        user.zipcode,
        user.address2
    )

    name = HumanName(user.alias)  # alias assumed never none

    guid = generate_guid()
    user_ids_to_guids[user.id] = guid

    query = ("INSERT INTO users ("
             "guid, "
             "auth_user_type, "
             "agency_ein, "
             "is_super, "
             "is_agency_active, "
             "is_agency_admin, "
             "first_name, "
             "middle_initial, "
             "last_name, "
             "email, "
             "email_validated, "
             "terms_of_use_accepted, "
             "title, "
             "organization, "
             "phone_number, "
             "fax_number, "
             "mailing_address) "
             "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")

    CUR_V2.execute(query, (
        guid,  # guid
        auth_user_type,  # auth_user_type
        agency_ein,  # agency_ein
        False,  # is_super
        user.is_staff,  # is_agency_active
        user.role == role_name.AGENCY_ADMIN,  # is_agency_admin
        name.first.title().strip(),  # first_name
        name.middle[0].upper() if name.middle else None,  # middle_initial
        name.last.title().strip(),  # last_name
        user.email,  # email
        is_active,  # email_validated
        is_active,  # terms_of_user_accepted
        None,  # title
        None,  # organization
        user.phone if user.phone != 'None' else None,  # phone_number
        user.fax if user.fax != 'None' else None,  # fax_number
        json.dumps(mailing_address)  # mailing_address
    ))
def transfer_users(user_ids_to_guids, user):
    """
    Agency users are determined by the presence of a department_id, otherwise
    a user is stored as anonymous.
    A user's first and last name and middle initial are parsed from `alias`.

    :param user_ids_to_guids: empty dictionary that will be populated

    """
    # get agency_ein and auth_user_type
    auth_user_type = user_type_auth.AGENCY_LDAP_USER
    is_active = False
    if user.department_id:
        CUR_V1.execute("SELECT name FROM department WHERE id = %s" %
                       user.department_id)
        agency_ein = AGENCY_V1_NAME_TO_EIN[CUR_V1.fetchone().name]
        is_active = True
    else:
        agency_ein = None
        auth_user_type = user_type_auth.ANONYMOUS_USER

    mailing_address = create_mailing_address(user.address1, user.city,
                                             user.state, user.zipcode,
                                             user.address2)

    name = HumanName(user.alias)  # alias assumed never none

    guid = generate_guid()
    user_ids_to_guids[user.id] = guid

    query = (
        "INSERT INTO users ("
        "guid, "
        "auth_user_type, "
        "agency_ein, "
        "is_super, "
        "is_agency_active, "
        "is_agency_admin, "
        "first_name, "
        "middle_initial, "
        "last_name, "
        "email, "
        "email_validated, "
        "terms_of_use_accepted, "
        "title, "
        "organization, "
        "phone_number, "
        "fax_number, "
        "mailing_address) "
        "VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
    )

    CUR_V2.execute(
        query,
        (
            guid,  # guid
            auth_user_type,  # auth_user_type
            agency_ein,  # agency_ein
            False,  # is_super
            user.is_staff,  # is_agency_active
            user.role == role_name.AGENCY_ADMIN,  # is_agency_admin
            name.first.title().strip(),  # first_name
            name.middle[0].upper() if name.middle else None,  # middle_initial
            name.last.title().strip(),  # last_name
            user.email,  # email
            is_active,  # email_validated
            is_active,  # terms_of_user_accepted
            None,  # title
            None,  # organization
            user.phone if user.phone != 'None' else None,  # phone_number
            user.fax if user.fax != 'None' else None,  # fax_number
            json.dumps(mailing_address)  # mailing_address
        ))