Exemplo n.º 1
0
 def _create_system_account(self, username):
     if not AccountService.get_by_owner(username):
         logger.debug('create owner')
         AccountService.create(
             username=username,
             account_type=AccountType.NORMAL,
             email='*****@*****.**' % (username),
             password=username,
             phone='18511076831',
             name=username,
         )
Exemplo n.º 2
0
    def handle(self, *args, **options):
        self.stdout.write("Create a admin_ account:")
        self.stdout.flush()
        email = raw_input("Input your email:")
        if not email:
            logger.info("Email should not be empty")
            sys.exit(1)

        password = raw_input("Input your password:"******"Password should not be empty")
            sys.exit(1)

        phone = raw_input("Input your cell phone:")
        if not phone:
            logger.info("Cell phone should not be empty")
            sys.exit(1)


        account, error = AccountService.create(
            email=email,
            password=password,
            phone=phone,
            name=email[:email.find('@')],
            account_type=AccountType.HANKOU,
        )
        if error is not None:
            logger.error("Create admin_ account failed, %s" % error)
            sys.exit(1)

        account.user.is_superuser = True
        account.user.save()

        logger.info("Create admin_ account successful!")
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        request_data = request.data.get('data', {})
        validator = CreateDepartmentMembersValidator(data=request_data)
        if not validator.is_valid():
            return Response(console_response(code=1, msg=validator.errors))

        department_id = validator.validated_data.get('department_id')
        member_type = validator.validated_data.get('member_type')

        validator = self.get_create_member_validator(member_type)(
            data=request_data)
        if not validator.is_valid():
            return Response(console_response(code=1, msg=validator.errors))

        member_info = validator.validated_data.get('member_info')

        member, error = AccountService.create(**member_info)
        if error:
            return Response(
                console_response(code=1, ret_set={},
                                 msg='成员创建失败' + str(error)))
        elif DepartmentMemberService.join([member.user], department_id):
            # 创建成功 就加入到指定部门
            if member.type in AccountType.FINANCE_TYPES:
                permission_group_id_list = validator.validated_data.get(
                    'permission_group_id_list')
                new_member = AccountService.get_by_owner(member.user)
                groups = PermissionGroupService.gets(permission_group_id_list)
                count = UserPermissionService.append_groups(new_member, groups)
                ret_set = DepartmentMemberService.to_dict(new_member)
                if count == len(permission_group_id_list):
                    # create_payload = {
                    #     "owner": member.user.username,
                    #     "zone": request_data.get("zone", "bj")
                    # }
                    # create_resp = create_base_net(create_payload)
                    # if create_resp.get("ret_code"):
                    #     return Response(console_response(code=1, msg="创建成员子网失败"))
                    # ret_set["sub_net"] = create_resp.get("ret_set")[0]
                    #
                    return Response(console_response(ret_set=ret_set))
                else:
                    return Response(
                        console_response(code=1,
                                         ret_set=ret_set,
                                         msg='成员初始化权限失败'))
            elif member.type in AccountType.PORTAL_TYPES:
                new_member = AccountService.get_by_owner(member.user)
                ret_set = DepartmentMemberService.to_dict(new_member)
                return Response(console_response(ret_set=ret_set))

        else:
            AccountService.delete_by_username(member.user.username,
                                              really_delete=True)
            return Response(
                console_response(code=1, ret_set={}, msg='成员加入部门失败'))
Exemplo n.º 4
0
 def setUp(self):
     telphone = 18901177755
     self.creator = AccountService.create(
         '*****@*****.**',
         'admin',
         telphone
     )[0]
     self.users = [
         AccountService.create(
             '*****@*****.**' % (i + 1),
             'admin',
             telphone + i + 1
         )[0]
         for i in range(16)
         ]
     self.permissions = list()
     for i in range(16):
         permission = Permission(name='UnitTest-Permission-%02d' % (i + 1))
         permission.save()
         self.permissions.append(permission)
     super(BasePermissionHelperTestCase, self).setUp()
Exemplo n.º 5
0
    def setUp(self):
        super(AbstractTestCase, self).setUp()

        zone = ZoneModel.objects.first()
        self.zone = zone.name

        email = '*****@*****.**'
        password = '******'
        phone = '106900810045'
        name = '单元测试'
        account, err = AccountService.create(email, password, phone, name=name)
        account.save()
        self.account = account
        self.owner = account.user.username

        self.client = Client(enforce_csrf_checks=False)
        self.client.login(username=account.user.username, password=password)