示例#1
0
    def __init__(self, userid):
        # userid
        self.userid = userid

        # orgid
        org_user_info = OrgUserInfo(self.userid)
        self.org = org_user_info.get_org()

        if not self.org or self.org.status != 'npf':
            raise InvalidAffiliation
    def create_user(org_user_name,
                    org,
                    is_org_user=False,
                    is_org_admin=False,
                    password='******'):
        """
        Crete Users and maps them to the org if needed.

        org_user_name - string
        if is_org_user = True, the user will be mapped to the org
        if is_org_admin = True, the user will be made an org admin
        org - Org object
        """
        org_user = OcUser().setup_user(username=org_user_name,
                                       email=org_user_name + '@email.cc',
                                       first_name=org_user_name +
                                       '_first_name',
                                       last_name=org_user_name + '_last_name')

        if is_org_user:
            # mapping user to org
            oui = OrgUserInfo(org_user.id)
            oui.setup_orguser(org)

            # making a user an org admin
            if is_org_admin:
                oui.make_org_admin(org.id)

        org_user.set_password(password)
        org_user.save()
示例#3
0
    def setUp(self):
        """Set up test fixtures."""
        _TEST_UUID = uuid.uuid4()

        self.client = Client()

        # set up regular user
        userRegEmail = '*****@*****.**' % _TEST_UUID
        self.userReg = OcUser().setup_user(
            username=userRegEmail,
            email=userRegEmail,
        )

        # set up user with a npf affiliation
        userOrgEmail = '*****@*****.**' % _TEST_UUID
        self.userOrg = OcUser().setup_user(
            username=userOrgEmail,
            email=userOrgEmail,
        )

        # set up user with a biz affiliation
        userBizEmail = '*****@*****.**' % _TEST_UUID
        self.userBiz = OcUser().setup_user(
            username=userBizEmail,
            email=userBizEmail,
        )

        # set up test org
        self.orgTest = OcOrg().setup_org(
            name='test_org_existing',
            status='npf'
        )

        # link org user to test org
        OrgUserInfo(self.userOrg.id).setup_orguser(self.orgTest)

        # user email used in tests
        self.test_email = '*****@*****.**' % _TEST_UUID
        Token.objects.filter(email=self.test_email).delete()

        # org users in tests
        self.test_org_name = 'test_org_%s' % _TEST_UUID
def setup_users():
    users_all = []
    for fxt in fixtures_user:
        try:
            user = OcUser().setup_user(fxt['email'], fxt['email'],
                                       fxt['firstname'], fxt['lastname'])
            print 'Created user %s' % user.username
        except UserExistsException:
            user = User.objects.get(email=fxt['email'])
            print 'User %s already exists' % fxt['email']

        user.set_password('oc')
        user.save()
        users_all.append(user)

        if fxt['type'] != 'volunteer':
            org = None
            orgname = fxt['lastname'].strip('Admin')
            try:
                org = Org.objects.get(name=orgname)
            except Exception as e:
                print 'No org named %s (%s)' % (orgname, org.name)
                return

            oui = OrgUserInfo(user.id)

            try:
                oui.setup_orguser(org)
            except InvalidOrgUserException:
                print 'Unable to configure %s <=> %s mapping (possible it already exists)' % (
                    org.name, fxt['email'])

            try:
                oui.make_org_admin(org.id)
            except InvalidOrgException:
                print 'Unable to grant admin privilege to %s on org %s (check for exitence of admin group)' % (
                    user.username, org.name)
            except ExistingAdminException:
                print '%s already granted admin privilege on org %s' % (
                    user.username, org.name)

    return users_all
示例#5
0
def _create_test_user(
    user_name,
    password='******',
    org=None,
    is_org_admin=False
):
    """
    Create users and maps them to the org if needed.

    Takes:
        user_name - string

        org - Org object. A NPF admin will be created, if Org is provided and is_org_admin = True.
        An org user will be created if org is provided and is_org_admin = False.
        If no org provided - a volunteer will be created.

        is_org_admin - if True, the user will be made an org admin, if org is provided.
    """
    test_user = OcUser().setup_user(
        username=user_name,
        email=user_name + '@email.cc',
        first_name=user_name + '_first_name',
        last_name=user_name + '_last_name'
    )

    if org:
        # mapping user to org
        oui = OrgUserInfo(test_user.id)
        oui.setup_orguser(org)

        # making a user an org admin
        if is_org_admin:
            oui.make_org_admin(org.id)

    test_user.set_password(password)
    test_user.save()
    return test_user
示例#6
0
users = User.objects.filter(is_staff=False)

data = {}
for user in users:
    try:
        us = user.usersettings
    except UserSettings.DoesNotExist:
        continue

    ocuser = OcUser(user.id)
    print user.id
    hours_req = ocuser.get_hours_requested()

    for req in hours_req:
        admin_user = req.user
        orguserinfo = OrgUserInfo(admin_user.id)
        is_approved = False
        try:
            is_approved = orguserinfo.is_org_admin()
        except:
            pass
        is_approved_with_org = orguserinfo.is_org_admin(
            req.usertimelog.event.project.org.id)

        data[req.id] = {
            'user_id':
            req.usertimelog.user.id,
            'user_email':
            req.usertimelog.user.email,
            'admin_email':
            req.user.email,
示例#7
0
 def __init__(self, userid):
     self.userid = userid
     orguserinfo = OrgUserInfo(userid)
     self.org = orguserinfo.get_org()
示例#8
0
from openCurrents.interfaces.orgs import OrgUserInfo
from openCurrents.interfaces.orgadmin import OrgAdmin

from openCurrents.models import OrgUser
from django.contrib.auth.models import User

from csv import writer
from datetime import datetime, timedelta
from pytz import utc

orgusers = OrgUser.objects.filter(org__status='npf')

data = {}
for orguser in orgusers:
    user = orguser.user
    orguserinfo = OrgUserInfo(user.id)
    is_approved = orguserinfo.is_org_admin()

    orgadmin = OrgAdmin(user.id)
    hours_req = orgadmin.get_hours_requested()
    hours_app = orgadmin.get_hours_approved()
    hours_total_pending = orgadmin.get_total_hours_pending()
    hours_total_approved_all = orgadmin.get_total_hours_issued()
    hours_total_approved_last_week = sum([
        common.diffInHours(rec.usertimelog.event.datetime_start,
                           rec.usertimelog.event.datetime_end)
        for rec in hours_app
        if rec.date_created > datetime.now(tz=utc) - timedelta(weeks=1)
    ])

    data[user.id] = {