Exemple #1
0
def get_user_info(request):
    if VERSIONS.active >= 3:
        user = user_get(request, request.user.id, admin=False)
        email = user.email
        name = user.name
    else:
        email = request.user.username
        name = email

    return email, name
Exemple #2
0
def checkowner2(instance):
    try:
        user_id = instance.user_id
        request = instance.request
        user = keystone.user_get(request, user_id)
    except:
        LOG.error(
            "Check owner2 checkowner2 exception fired /home/horizon/horizon/openstack_dashboard/dashboards/admin/instances/tables.py"
        )

    return user.name
Exemple #3
0
    def get_user(self, user_id):
        """Returns user fetched from API.

        Caching the result, so it doesn't contact API twice with the
        same query.
        """

        user = self._users.get(user_id, None)
        if not user:
            user = keystone.user_get(self._request, user_id)
            # caching the user, for later use
            self._users[user_id] = user
        return user
Exemple #4
0
    def get_user(self, user_id):
        """Returns user fetched form API

        Caching the result, so it doesn't contact API twice with the
        same query
        """

        user = self._users.get(user_id, None)
        if not user:
            user = keystone.user_get(self._request, user_id)
            # caching the user, for later use
            self._users[user_id] = user
        return user
def checkowner2(instance):
    try:
        user_id = instance.user_id
        request = instance.request
        user = keystone.user_get(request, user_id)
        username = user.name
    except:
        LOG.error(
            "Check owner2 checkowner2 exception fired /home/horizon/horizon/openstack_dashboard/dashboards/project/instances/tables.py"
        )
        username = "******"

    return username
Exemple #6
0
def get_project_managers(request, project_id):
    result = list()

    kclient = keystone_api.keystoneclient(request, admin=True)
    tntadm_role_id = get_admin_roleid(request)
    
    url = '/role_assignments?scope.project.id=%s&role.id=%s'
    resp, body = kclient.get(url % (project_id, tntadm_role_id))
    
    for item in body['role_assignments']:
        tntadmin = keystone_api.user_get(request, item['user']['id'])
        LOG.debug('Found tenant admin %s' % tntadmin.name)
        result.append(tntadmin)
        
    return result
Exemple #7
0
    def handle(self, request, data):
    
        try:
            tenantadmin_roleid, default_roleid = check_and_get_roleids(request)
            usr_and_prj = data['requestid'].split(':')

            with transaction.atomic():
                q_args = {
                    'registration__regid' : int(usr_and_prj[0]),
                    'project__projectname' : usr_and_prj[1]
                }
                prj_req = PrjRequest.objects.filter(**q_args)[0]
                

                project_name = prj_req.project.projectname
                project_id = prj_req.project.projectid
                user_name = prj_req.registration.username
                user_id = prj_req.registration.userid
                
                #
                # clear request
                #
                prj_req.delete()

            #
            # send notification to project managers and users
            #
            user_email = keystone_api.user_get(request, user_id).email
            
            prjman_list = get_project_managers(request, project_id)
            noti_params = {
                'username' : user_name,
                'project' : project_name,
                'notes' : data['reason']
            }

            noti_sbj, noti_body = notification_render(SUBSCR_FORCED_NO_TYPE, noti_params)
            notifyUsers([ pman.email for pman in prjman_list ], noti_sbj, noti_body)
            
            noti_sbj, noti_body = notification_render(SUBSCR_NO_TYPE, noti_params)
            notifyUsers(user_email, noti_sbj, noti_body)
                
        except:
            LOG.error("Error forced-checking request", exc_info=True)
            messages.error(request, _("Cannot forced check request"))
            return False

        return True
Exemple #8
0
    def handle(self, request, data):
    
        try:

            tenantadmin_roleid, default_roleid = check_and_get_roleids(request)
            usr_and_prj = data['requestid'].split(':')

            with transaction.atomic():

                #
                # Creation of new tenant
                #
                q_args = {
                    'registration__regid' : int(usr_and_prj[0]),
                    'project__projectname' : usr_and_prj[1]
                }
                prj_req = PrjRequest.objects.filter(**q_args)[0]
                
                project_name = prj_req.project.projectname
                user_id = prj_req.registration.userid
                
                #
                # Clear request
                #
                prj_req.delete()
                
            #
            # Send notification to the user
            #
            user_email = keystone_api.user_get(request, user_id).email
            noti_params = {
                'project' : project_name,
                'notes' : data['reason']
            }

            noti_sbj, noti_body = notification_render(PRJ_REJ_TYPE, noti_params)
            notifyUsers(user_email, noti_sbj, noti_body)

        except:
            LOG.error("Error pre-checking project", exc_info=True)
            messages.error(request, _("Cannot pre-check project"))
            return False

        return True
    def handle(self, request, data):

        if not request.user.is_superuser:
            messages.error(_("Operation not authorized"))
            return False

        try:

            with transaction.atomic():
                reg_user = Registration.objects.filter(userid=data['userid'])[0]
                prj_list = Project.objects.filter(projectname__in=data['projects'])

                reg_user.expdate = data['expdate']
                reg_user.save()

                #
                # Enable reminder for cloud admin if present
                #
                RegRequest.objects.filter(
                    registration = reg_user,
                    flowstatus = RSTATUS_REMINDER
                ).update(flowstatus = RSTATUS_REMINDACK)

                k_user = keystone_api.user_get(request, data['userid'])
                if not k_user.enabled:
                    keystone_api.user_update(request, data['userid'], enabled=True)

        except:
            LOG.error("Generic failure", exc_info=True)
            return False

        for prj_item in prj_list:

            try:
                with transaction.atomic():
                    Expiration(
                        registration=reg_user,
                        project=prj_item,
                        expdate=data['expdate']
                    ).save()

                    keystone_api.add_tenant_user_role(
                        request, prj_item.projectid,
                        data['userid'], get_default_role(request))

                #
                # send notification to project managers and users
                #
                tmpres = EMail.objects.filter(registration__userid=data['userid'])
                user_email = tmpres[0].email if tmpres else None

                m_userids = get_prjman_ids(request, prj_item.projectid)
                tmpres = EMail.objects.filter(registration__userid__in=m_userids)
                m_emails = [ x.email for x in tmpres ]

                noti_params = {
                    'username' : reg_user.username,
                    'project' : prj_item.projectname
                }

                notifyProject(request=self.request, rcpt=m_emails,
                              action=SUBSCR_FORCED_OK_TYPE, context=noti_params,
                              dst_project_id=prj_item.projectid)
                notifyUser(request=self.request, rcpt=user_email,
                           action=SUBSCR_OK_TYPE, context=noti_params,
                           dst_project_id=prj_item.projectid,
                           dst_user_id=reg_user.userid)

            except:
                LOG.error("Generic failure", exc_info=True)
        return True
    def handle(self, request, data):

        if not request.user.is_superuser:
            messages.error(_("Operation not authorized"))
            return False

        try:

            with transaction.atomic():
                reg_user = Registration.objects.filter(userid=data['userid'])[0]
                prj_list = Project.objects.filter(projectname__in=data['projects'])

                reg_user.expdate = data['expdate']
                reg_user.save()

                k_user = keystone_api.user_get(request, data['userid'])
                if not k_user.enabled:
                    keystone_api.user_update(request, data['userid'], enabled=True)

        except:
            LOG.error("Generic failure", exc_info=True)
            return False

        for prj_item in prj_list:

            try:
                with transaction.atomic():
                    Expiration(
                        registration=reg_user,
                        project=prj_item,
                        expdate=data['expdate']
                    ).save()

                    keystone_api.add_tenant_user_role(
                        request, prj_item.projectid,
                        data['userid'], get_default_role(request))

                #
                # send notification to project managers and users
                #
                tmpres = EMail.objects.filter(registration__userid=data['userid'])
                user_email = tmpres[0].email if tmpres else None

                m_userids = get_prjman_ids(request, prj_item.projectid)
                tmpres = EMail.objects.filter(registration__userid__in=m_userids)
                m_emails = [ x.email for x in tmpres ]

                noti_params = {
                    'username' : reg_user.username,
                    'project' : prj_item.projectname
                }

                notifyProject(request=self.request, rcpt=m_emails,
                              action=SUBSCR_FORCED_OK_TYPE, context=noti_params,
                              dst_project_id=prj_item.projectid)
                notifyUser(request=self.request, rcpt=user_email,
                           action=SUBSCR_OK_TYPE, context=noti_params,
                           dst_project_id=prj_item.projectid,
                           dst_user_id=reg_user.userid)

            except:
                LOG.error("Generic failure", exc_info=True)
        return True
Exemple #11
0
    def handle(self, request, data):
    
        try:

            tenantadmin_roleid, default_roleid = check_and_get_roleids(request)
            usr_and_prj = data['requestid'].split(':')

            with transaction.atomic():

                #
                # Creation of new tenant
                #
                q_args = {
                    'registration__regid' : int(usr_and_prj[0]),
                    'project__projectname' : usr_and_prj[1]
                }
                prj_req = PrjRequest.objects.filter(**q_args)[0]
                
                project_name = prj_req.project.projectname
                user_id = prj_req.registration.userid
                
                kprj = keystone_api.tenant_create(request, project_name,
                                                    prj_req.project.description, True)
                prj_req.project.projectid = kprj.id
                prj_req.project.save()
                LOG.info("Created tenant %s" % project_name)
                
                #
                # The new user is the project manager of its tenant
                #
                keystone_api.add_tenant_user_role(request, prj_req.project.projectid,
                                                user_id, tenantadmin_roleid)


                #
                # Insert expiration date per tenant
                #
                expiration = Expiration()
                expiration.registration = prj_req.registration
                expiration.project = prj_req.project
                expiration.expdate = data['expiration']
                expiration.save()

                #
                # Update the max expiration per user
                #
                user_reg = prj_req.registration
                if data['expiration'] > user_reg.expdate:
                    user_reg.expdate = data['expiration']
                    user_reg.save()

                #
                # Clear request
                #
                prj_req.delete()
                
            #
            # Send notification to the user
            #
            user_email = keystone_api.user_get(request, user_id).email
            noti_params = {
                'project' : project_name
            }

            noti_sbj, noti_body = notification_render(PRJ_CREATE_TYPE, noti_params)
            notifyUsers(user_email, noti_sbj, noti_body)

        except:
            LOG.error("Error pre-checking project", exc_info=True)
            messages.error(request, _("Cannot pre-check project"))
            return False

        return True