def put(self, request, *args, **kwargs): """ 修改开启、关闭注册状态 """ user_id = request.user.user_id enterprise_id = request.user.enterprise_id admin = enterprise_user_perm_repo.is_admin(user_id=user_id, eid=enterprise_id) is_regist = request.data.get("is_regist") if admin: if is_regist is False: # 修改全局配置 platform_config_service.update_config("IS_REGIST", { "enable": False, "value": None }) return Response(general_message(200, "close register", "关闭注册"), status=200) else: platform_config_service.update_config("IS_REGIST", { "enable": True, "value": None }) return Response(general_message(200, "open register", "开启注册"), status=200) else: return Response(general_message(400, "no jurisdiction", "没有权限"), status=400)
def initial(self, request, *args, **kwargs): self.user = request.user self.enterprise = TenantEnterprise.objects.filter(enterprise_id=self.user.enterprise_id).first() self.is_enterprise_admin = enterprise_user_perm_repo.is_admin(self.user.enterprise_id, self.user.user_id) self.get_perms() self.check_perms(request, *args, **kwargs) self.tenant_name = kwargs.get("tenantName", None) if self.tenant_name: try: self.tenant = Tenants.objects.get(tenant_name=self.tenant_name, enterprise_id=self.user.enterprise_id) self.team = self.tenant except Tenants.DoesNotExist: raise ServiceHandleException(msg="team not found", msg_show="团队不存在")
def is_user_admin_in_current_enterprise(self, current_user, enterprise_id): """判断用户在该企业下是否为管理员""" if current_user.enterprise_id != enterprise_id: return False is_admin = enterprise_user_perm_repo.is_admin(enterprise_id, current_user.user_id) if is_admin: return True users = user_repo.get_enterprise_users(enterprise_id).order_by("user_id") if users: admin_user = users[0] # 如果有,判断用户最开始注册的用户和当前用户是否为同一人,如果是,添加数据返回true if admin_user.user_id == current_user.user_id: token = self.generate_key() enterprise_user_perm_repo.create_enterprise_user_perm(current_user.user_id, enterprise_id, "admin", token) return True return False