def create_user(request): user = User() form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) if not form.is_valid(): return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: link_user_to_dc_task(user, DataCenter.get_default()) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': link_user_to_dc_task(user, DataCenter.get_default()) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({"success": True, "msg": _("User is created successfully!")})
def create_user(request): user = User() form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) if not form.is_valid(): return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: link_user_to_dc_task(user, DataCenter.get_default()) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': link_user_to_dc_task(user, DataCenter.get_default()) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({ "success": True, "msg": _("User is created successfully!") })
def grant_workflow_approve(request): user_id = request.data['user_id'] user = UserProxy.objects.get(pk=user_id) UserProxy.grant_workflow_approve(user) msg = _("User %(name)s can approve workflow now!") return Response({"success": True, "msg": msg % {'name': user.username}})
def cloud(request): if request.user.is_superuser: return redirect('management') if not (UserProxy.has_any_data_center(request.user) or UserProxy.can_approve_workflow(request.user)): return redirect('no_udc') return render(request, "cloud.html")
def revoke_workflow_approve(request): user_id = request.data['user_id'] user = UserProxy.objects.get(pk=user_id) if Step.objects.filter(approver=user).exists(): msg = _("Cannot revoke workflow approve permission from %(name)s, " "this user is now an approver of some workflows.") return Response({"success": False, "msg": msg % {'name': user.username}}) UserProxy.revoke_workflow_approve(user) msg = _("User %(name)s cannot approve workflow any more!") return Response({"success": True, "msg": msg % {'name': user.username}})
def create_user(request): LOG.info("****** start to create user *****") LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) LOG.info("****** password is ******" + str(request.data['password1'])) user = User() LOG.info("ccccccccccccc") form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) LOG.info("ddddddddddddd") if not form.is_valid(): LOG.info("form is not valid") return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() #update start if settings.TRI_ENABLED and request.data['is_system_user'] == 'true': LOG.info("******** I am systemuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) UserProxy.grant_system_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true': LOG.info("******** I am safetyuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_safety_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true': LOG.info("******** I am audituser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_audit_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: tenant_id = request.data['tenant'] LOG.info("tennat_id is " + str(tenant_id)) password = request.data['password1'] link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': tenant_id = request.data['tenant'] link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({ "success": True, "msg": _("User is created successfully!") })
def create_user(request): LOG.info("****** start to create user *****") LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) LOG.info("****** password is ******" + str(request.data['password1'])) user = User() LOG.info("ccccccccccccc") form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) LOG.info("ddddddddddddd") if not form.is_valid(): LOG.info("form is not valid") return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() #update start if settings.TRI_ENABLED and request.data['is_system_user'] == 'true': LOG.info("******** I am systemuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) UserProxy.grant_system_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true': LOG.info("******** I am safetyuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_safety_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true': LOG.info("******** I am audituser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_audit_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: tenant_id = request.data['tenant'] LOG.info("tennat_id is " + str(tenant_id)) password = request.data['password1'] link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': tenant_id = request.data['tenant'] link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({"success": True, "msg": _("User is created successfully!")})
def create_user(request): LOG.info("****** start to create user *****") LOG.info("******* data is ******" + str(request.data)) LOG.info("****** username is ******" + str(request.data['username'])) posted_username = request.data['username'] if str(posted_username) in ['neutron', 'cinder', 'keystone', 'nova', 'glance', 'heat', 'swift', 'admin', 'ceilometer']: return Response({"success": False, "msg": _("Service user must not be created.")}) LOG.info("****** password is ******" + str(request.data['password1'])) user = User() LOG.info("ccccccccccccc") form = CloudUserCreateFormWithoutCapatcha(data=request.POST, instance=user) LOG.info("ddddddddddddd") if not form.is_valid(): LOG.info("form is not valid") return Response({"success": False, "msg": _("Data is not valid")}) user = form.save() #update start if settings.TRI_ENABLED and request.data['is_system_user'] == 'true': LOG.info("******** I am systemuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) UserProxy.grant_system_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_safety_user'] == 'true': LOG.info("******** I am safetyuser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_safety_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) if settings.TRI_ENABLED and request.data['is_audit_user'] == 'true': LOG.info("******** I am audituser ***************") #user = User.objects.create_superuser(username=username, email=email, password=password1) LOG.info("******** SUPERUSER CREATE SUCCESS **********") UserProxy.grant_audit_user(user) LOG.info("fffffffffff") #return Response({"success": True, # "msg": _("User is created successfully!")}) # If workflow is disabled, then only resrouce user can be created, # otherwise admin can create resource user and workflow approver user. if not settings.WORKFLOW_ENABLED: tenant_id = request.data['tenant'] LOG.info("tennat_id is " + str(tenant_id)) password = request.data['password1'] link_user_to_dc_task.delay(user, DataCenter.get_default(), tenant_id, password) try: operation = Operation(user=request.user, udc_id=request.session['UDC_ID'], resource='用户', resource_id=1, resource_name='用户',action="创建用户", result=1) operation.save() except Exception as e: LOG.info(str(e)) else: if 'is_resource_user' in request.data and \ request.data['is_resource_user'] == 'true': tenant_id = request.data['tenant'] link_user_to_dc_task(user, DataCenter.get_default(), tenant_id, password) if 'is_approver' in request.data and \ request.data['is_approver'] == 'true': UserProxy.grant_workflow_approve(user) return Response({"success": True, "msg": _("User is created successfully!")})