Example #1
0
    def _create_project(self, request, data):

        result = super(ExtCreateProject, self)._create_project(request, data)
        if not result:
            return None

        with transaction.atomic():

            newprj_id = self.object.id

            qargs = {
                'projectname': data['name'],
                'projectid': newprj_id,
                'description': data['description'],
                'status': PRJ_GUEST if data.get('guest', False) else PRJ_PUBLIC
            }
            newprj = Project(**qargs)
            newprj.save()
            self.this_project = newprj

        return result
    def _create_project(self, request, data):

        result = super(ExtCreateProject, self)._create_project(request, data)
        if not result:
            return None

        with transaction.atomic():

            newprj_id = self.object.id

            qargs = {
                "projectname": data["name"],
                "projectid": newprj_id,
                "description": data["description"],
                "status": PRJ_GUEST if data.get("guest", False) else PRJ_PUBLIC,
            }
            newprj = Project(**qargs)
            newprj.save()
            self.this_project = newprj

        return result
 def get_data(self):
     result = list()
     marker = self.request.GET.get(ProjectsTable._meta.pagination_param, None)
     domain_context = self.request.session.get('domain_context', None)
     try:
         tenants, self._more = api.keystone.tenant_list(
             self.request, domain=domain_context,
             paginate=True, marker=marker)
         
         prj_table = dict()
         for item in tenants:
             prj_table[item.name] = ExtPrjItem(item)
         
         prj_list = Project.objects.filter(projectname__in=prj_table.keys())
         for prj_item in prj_list:
             prj_table[prj_item.projectname].status = prj_item.status
             prj_table[prj_item.projectname].checked = True
         
         # Auto-import of external projects
         for item in prj_table:
             if not prj_table[item].checked:
                 p_query = {
                     'projectname' : prj_table[item].name,
                     'projectid' : prj_table[item].id,
                     'description' : prj_table[item].description,
                     'status' : PRJ_PRIVATE
                 }
                 imprj = Project(**p_query)
                 imprj.save()
         
         tmplist = prj_table.keys()
         tmplist.sort()
         for item in tmplist:
             result.append(prj_table[item])
         
     except Exception:
         self._more = False
         exceptions.handle(self.request, _("Unable to retrieve project list."))
     return result
Example #4
0
 def get_data(self):
 
     import_guest_project()
     
     result = list()
     try:
         tenants = super(IndexView, self).get_data()
         if len(tenants) == 0:
             return result
         
         prj_table = dict()
         for item in tenants:
             prj_table[item.name] = ExtPrjItem(item)
         
         prj_list = Project.objects.filter(projectname__in=prj_table.keys())
         for prj_item in prj_list:
             prj_table[prj_item.projectname].status = prj_item.status
             prj_table[prj_item.projectname].checked = True
         
         # Auto-import of external projects
         for item in prj_table:
             if not prj_table[item].checked:
                 p_query = {
                     'projectname' : prj_table[item].name,
                     'projectid' : prj_table[item].id,
                     'description' : prj_table[item].description,
                     'status' : PRJ_PRIVATE
                 }
                 imprj = Project(**p_query)
                 imprj.save()
         
         tmplist = prj_table.keys()
         tmplist.sort()
         for item in tmplist:
             result.append(prj_table[item])
         
     except Exception:
         exceptions.handle(self.request, _("Unable to retrieve project list."))
     return result
Example #5
0
    def handle(self, request, data):

        new_name = data['name']
        new_desc = data['description']
        project_id = data['project_id']

        with transaction.atomic():
            #
            # TODO missing index
            #
            pr_list = Project.objects.filter(projectid=project_id)

            if len(pr_list) == 0:
                LOG.error("Missing project %s in database" % project_id)
                return False
            else:
                self.this_project = pr_list[0]

            if new_name == self.this_project.projectname:
                #
                # Change project description
                #
                self.this_project.description = new_desc
                self.this_project.save()
            else:
                #
                # Change project name and description
                #
                newpr = Project()
                newpr.projectname = new_name
                newpr.projectid = project_id
                newpr.description = new_desc
                newpr.status = self.this_project.status
                newpr.save()

                PrjRequest.objects.filter(project=self.this_project).update(
                    project=newpr)
                Expiration.objects.filter(project=self.this_project).update(
                    project=newpr)
                self.this_project.delete()
                self.this_project = newpr

            if not super(ExtUpdateProject, self).handle(request, data):
                raise IntegrityError('Cannot complete update on Keystone')

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

        new_name = data["name"]
        new_desc = data["description"]
        project_id = data["project_id"]

        with transaction.atomic():
            #
            # TODO missing index
            #
            pr_list = Project.objects.filter(projectid=project_id)

            if len(pr_list) == 0:
                LOG.error("Missing project %s in database" % project_id)
                return False
            else:
                self.this_project = pr_list[0]

            if new_name == self.this_project.projectname:
                #
                # Change project description
                #
                self.this_project.description = new_desc
                self.this_project.save()
            else:
                #
                # Change project name and description
                #
                newpr = Project()
                newpr.projectname = new_name
                newpr.projectid = project_id
                newpr.description = new_desc
                newpr.status = self.this_project.status
                newpr.save()

                PrjRequest.objects.filter(project=self.this_project).update(project=newpr)
                Expiration.objects.filter(project=self.this_project).update(project=newpr)
                self.this_project.delete()
                self.this_project = newpr

            if not super(ExtUpdateProject, self).handle(request, data):
                raise IntegrityError("Cannot complete update on Keystone")

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

        new_name=data['name']
        new_desc = data['description']
        project_id = data['project_id']

        with transaction.atomic():

            pr_list = Project.objects.filter(projectid=project_id)
            
            if len(pr_list) == 0:
                LOG.error("Missing project %s in database" % project_id)
                return False
            else:
                self.this_project = pr_list[0]

            if new_name == self.this_project.projectname:
                #
                # Change project description
                #
                self.this_project.description = new_desc
                self.this_project.save()
            else:
                #
                # Change project name and description
                #
                newpr = Project()
                newpr.projectname = new_name
                newpr.projectid = project_id
                newpr.description = new_desc
                newpr.status = self.this_project.status
                newpr.save()

                old_reqs = PrjRequest.objects.filter(project=self.this_project)
                for item in old_reqs:
                    PrjRequest(
                        registration = item.registration,
                        project = newpr,
                        flowstatus = item.flowstatus,
                        notes = item.notes
                    ).save()
                old_reqs.delete()

                old_exps = Expiration.objects.filter(project=self.this_project)
                for item in old_exps:
                    Expiration(
                        registration = item.registration,
                        project = newpr,
                        expdate = item.expdate
                    ).save()
                old_exps.delete()

                old_rules = PrjRole.objects.filter(project=self.this_project)
                for item in old_rules:
                    PrjRole(
                        registration = item.registration,
                        project = newpr,
                        roleid = item.roleid,
                        status = item.status
                    ).save()
                old_rules.delete()

                self.this_project.delete()
                self.this_project = newpr
            
            if not super(ExtUpdateProject, self).handle(request, data):
                raise IntegrityError('Cannot complete update on Keystone')

        return True
    def _update_project_members(self, request, data, project_id):
        
        admin_role_id = None
        available_roles = baseWorkflows.api.keystone.role_list(request)
        member_ids = set()
        prjadm_ids = set()
        result = None
        
        with transaction.atomic():

            #
            # Create project in the database
            #
            newprj_id = self.object.id

            qargs = {
                'projectname' : data['name'],
                'projectid' : newprj_id,
                'description' : data['description'],
                'status' : PRJ_PUBLIC
            }
            newprj = Project(**qargs)
            newprj.save()
            self.this_project = newprj

            #
            # Setup members
            #
            for role in available_roles:
            
                tmp_step = self.get_step(baseWorkflows.PROJECT_USER_MEMBER_SLUG)
                field_name = tmp_step.get_member_field_name(role.id)

                if role.name == TENANTADMIN_ROLE:
                    admin_role_id = role.id
                    for tmpid in data[field_name]:
                        prjadm_ids.add(tmpid)

                for user_id in data[field_name]:
                    member_ids.add(user_id)


            #
            # Import expiration per tenant, use per-user expiration date as a fall back
            # Create the project admin cache
            #
            for u_item in Registration.objects.filter(userid__in=member_ids):

                new_p_exp = Expiration()
                new_p_exp.registration = u_item
                new_p_exp.project = self.this_project
                new_p_exp.expdate = u_item.expdate
                new_p_exp.save()

                if u_item.userid in prjadm_ids:
                    new_prjrole = PrjRole()
                    new_prjrole.registration = u_item
                    new_prjrole.project = self.this_project
                    new_prjrole.roleid = admin_role_id
                    new_prjrole.save()
                    LOG.debug("Created prj admin: %s" % u_item.username)

            #
            # Insert cloud admin as project_manager if missing
            #
            if len(prjadm_ids) == 0:
                baseWorkflows.api.keystone.add_tenant_user_role(request, project_id,
                                                    request.user.id, admin_role_id)

            result = super(ExtCreateProject, self)._update_project_members(request, data, project_id)

        #
        # Notify users
        #
        for e_item in EMail.objects.filter(registration__userid__in=member_ids):
            noti_params = {
                'username' : e_item.registration.username,
                'project' : self.this_project.projectname,
                'isadmin' : e_item.registration.userid in prjadm_ids
            }
            notifyUser(request=request, rcpt=e_item.email, action=MEMBER_FORCED_ADD, context=noti_params,
                       dst_project_id=self.this_project.projectid, dst_user_id=e_item.registration.userid)

        #
        # Notify all cloud admins
        #
        notifyAdmin(request=request, action=NEWPRJ_BY_ADM,
                    context={'project' : self.this_project.projectname})        

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

        new_name = data['name']
        new_desc = data['description']
        project_id = data['project_id']

        with transaction.atomic():

            pr_list = Project.objects.filter(projectid=project_id)

            if len(pr_list) == 0:
                LOG.error("Missing project %s in database" % project_id)
                return False
            else:
                self.this_project = pr_list[0]

            if new_name == self.this_project.projectname:
                #
                # Change project description
                #
                self.this_project.description = new_desc
                self.this_project.save()
            else:
                #
                # Change project name and description
                #
                newpr = Project()
                newpr.projectname = new_name
                newpr.projectid = project_id
                newpr.description = new_desc
                newpr.status = self.this_project.status
                newpr.save()

                old_reqs = PrjRequest.objects.filter(project=self.this_project)
                for item in old_reqs:
                    PrjRequest(registration=item.registration,
                               project=newpr,
                               flowstatus=item.flowstatus,
                               notes=item.notes).save()
                old_reqs.delete()

                old_exps = Expiration.objects.filter(project=self.this_project)
                for item in old_exps:
                    Expiration(registration=item.registration,
                               project=newpr,
                               expdate=item.expdate).save()
                old_exps.delete()

                old_rules = PrjRole.objects.filter(project=self.this_project)
                for item in old_rules:
                    PrjRole(registration=item.registration,
                            project=newpr,
                            roleid=item.roleid,
                            status=item.status).save()
                old_rules.delete()

                self.this_project.delete()
                self.this_project = newpr

            if not super(ExtUpdateProject, self).handle(request, data):
                raise IntegrityError('Cannot complete update on Keystone')

        return True
    def _update_project_members(self, request, data, project_id):

        admin_role_id = None
        available_roles = baseWorkflows.api.keystone.role_list(request)
        member_ids = set()
        prjadm_ids = set()
        result = None

        with transaction.atomic():

            #
            # Create project in the database
            #
            newprj_id = self.object.id

            qargs = {
                'projectname': data['name'],
                'projectid': newprj_id,
                'description': data['description'],
                'status': PRJ_PUBLIC
            }
            newprj = Project(**qargs)
            newprj.save()
            self.this_project = newprj

            #
            # Setup members
            #
            for role in available_roles:

                tmp_step = self.get_step(
                    baseWorkflows.PROJECT_USER_MEMBER_SLUG)
                field_name = tmp_step.get_member_field_name(role.id)

                if role.name == TENANTADMIN_ROLE:
                    admin_role_id = role.id
                    for tmpid in data[field_name]:
                        prjadm_ids.add(tmpid)

                for user_id in data[field_name]:
                    member_ids.add(user_id)

            #
            # Import expiration per tenant, use per-user expiration date as a fall back
            # Create the project admin cache
            #
            for u_item in Registration.objects.filter(userid__in=member_ids):

                new_p_exp = Expiration()
                new_p_exp.registration = u_item
                new_p_exp.project = self.this_project
                new_p_exp.expdate = u_item.expdate
                new_p_exp.save()

                if u_item.userid in prjadm_ids:
                    new_prjrole = PrjRole()
                    new_prjrole.registration = u_item
                    new_prjrole.project = self.this_project
                    new_prjrole.roleid = admin_role_id
                    new_prjrole.save()
                    LOG.debug("Created prj admin: %s" % u_item.username)

            #
            # Insert cloud admin as project_manager if missing
            #
            if len(prjadm_ids) == 0:
                baseWorkflows.api.keystone.add_tenant_user_role(
                    request, project_id, request.user.id, admin_role_id)

            result = super(ExtCreateProject, self)._update_project_members(
                request, data, project_id)

        #
        # Notify users
        #
        for e_item in EMail.objects.filter(
                registration__userid__in=member_ids):
            noti_params = {
                'username': e_item.registration.username,
                'project': self.this_project.projectname,
                'isadmin': e_item.registration.userid in prjadm_ids
            }
            notifyUser(request=request,
                       rcpt=e_item.email,
                       action=MEMBER_FORCED_ADD,
                       context=noti_params,
                       dst_project_id=self.this_project.projectid,
                       dst_user_id=e_item.registration.userid)

        #
        # Notify all cloud admins
        #
        notifyAdmin(request=request,
                    action=NEWPRJ_BY_ADM,
                    context={'project': self.this_project.projectname})

        return result