def has_permission(self, request, view): config = SysConfig().get('api_user_whitelist') user_list = config.split(',') if config else [] api_user_whitelist = [int(uid) for uid in user_list] # 只有在api_user_whitelist参数中的用户才有权限 return request.user.id in api_user_whitelist
def init_user(user): """ 给用户关联默认资源组和权限组 :param user: :return: """ # 添加到默认权限组 default_auth_group = SysConfig().get('default_auth_group', '') if default_auth_group: default_auth_group = default_auth_group.split(',') [ user.groups.add(group) for group in Group.objects.filter(name__in=default_auth_group) ] # 添加到默认资源组 default_resource_group = SysConfig().get('default_resource_group', '') if default_resource_group: default_resource_group = default_resource_group.split(',') [ user.resource_group.add(group) for group in ResourceGroup.objects.filter( group_name__in=default_resource_group) ]