Exemple #1
0
 def delete(self, request, obj_id):
 
     try:
         
         roles_obj = client_factory(request).roles
         role_assign_obj = client_factory(request).role_assignments
         users_obj = client_factory(request).users
         
         arg_dict = {
             'project' : request.user.tenant_id,
             'user' : obj_id
         }
         for r_item in role_assign_obj.list(**arg_dict):
             roles_obj.revoke(r_item.role['id'], **arg_dict)
         
         member = users_obj.get(obj_id)
         noti_params = {
             'username' : member.name,
             'admin_address' : users_obj.get(request.user.id).email,
             'project' : request.user.tenant_name
         }
         noti_sbj, noti_body = notification_render(MEMBER_REMOVED, noti_params)
         notifyUsers(member.email, noti_sbj, noti_body)
         
         noti_sbj, noti_body = notification_render(MEMBER_REMOVED_ADM, noti_params)
         notifyManagers(noti_sbj, noti_body)
         
     except:
         LOG.error("Grant revoke error", exc_info=True)
         messages.error(request, _('Unable to delete member from tenant.'))
Exemple #2
0
    def handle(self, request, data):
    
        with transaction.atomic():
        
            registration = Registration.objects.filter(userid=request.user.id)[0]
        
            prj_action = data['prjaction']
            prjlist = list()
            if prj_action == 'selprj':
                for project in data['selprj']:
                    prjlist.append((project, "", PRJ_PUBLIC, False))
            
            elif prj_action == 'newprj':
                prjlist.append((
                    data['newprj'],
                    data['prjdescr'],
                    PRJ_PRIVATE if data['prjpriv'] else PRJ_PUBLIC,
                    True
                ))

        
            newprjlist = list()
            for prjitem in prjlist:
        
                if prjitem[3]:
                    try:

                        prjArgs = {
                            'projectname' : prjitem[0],
                            'description' : prjitem[1],
                            'status' : prjitem[2]
                        }
                        project = Project.objects.create(**prjArgs)
                        newprjlist.append(project.projectname)

                    except IntegrityError:
                        messages.error(request, _("Project %s already exists") % prjitem[0])
                        LOG.error("Cannot create project %s" % prjitem[0])
                        return False
                
                elif prjitem[0] in self.pendingProjects:
                    continue
                else:
                    project = Project.objects.get(projectname=prjitem[0])
                        
                reqArgs = {
                    'registration' : registration,
                    'project' : project,
                    'flowstatus' : PSTATUS_PENDING,
                    'notes' : data['notes']
                }                
                reqPrj = PrjRequest(**reqArgs)
                reqPrj.save()

            #
            # Send notification to cloud admins for project creation
            #
            for prj_name in newprjlist:
                noti_params = {
                    'username' : request.user.username,
                    'project' : prj_name
                }
                noti_sbj, noti_body = notification_render(NEWPRJ_REQ_TYPE, noti_params)
                notifyManagers(noti_sbj, noti_body)

            #
            # TODO implement notifications to project managers
            #
        
        return True