我有一个Session有:created_at日期和:start_time日期的模型,都存储在数据库中:time.我目前正在一个巨大的表上吐出一堆结果,并允许用户使用范围过滤单个日期和可选时间范围的结果,如下所示:
class Session < ActiveRecord::Base
...
scope :filter_by_date, lambda { |date|
date = date.split(",")[0]
where(:created_at =>
DateTime.strptime(date, '%m/%d/%Y')..DateTime.strptime(date, '%m/%d/%Y').end_of_day
)
}
scope :filter_by_time, lambda { |date, time|
to = time[:to]
from = time[:from]
where(:start_time =>
DateTime.strptime("#{date} #{from[:digits]} #{from[:meridian]}", '%m/%d/%Y %r')..
DateTime.strptime("#{date} #{to[:digits]} #{to[:meridian]}", '%m/%d/%Y %r')
)
}
end
Run Code Online (Sandbox Code Playgroud)
控制器看起来或多或少像这样:
class SessionController < ApplicationController
def index
if params.include?(:date) ||
params.include?(:time) &&
( params[:time][:from][:digits].present? && params[:time][:to][:digits].present? )
i = Session.scoped
i = i.filter_by_date(params[:date]) unless …Run Code Online (Sandbox Code Playgroud) 我找不到太多关于在yii中将默认范围应用于模型的文档,我想知道是否有人可以解释或指出我正确的方向.
我的问题的快速版本:
是否可以向默认范围添加关系,或者默认情况下为模型上的每个AR搜索添加"with"条件?
我的问题的长版本:
我的应用程序的快速摘要:
我有两个型号,provider和item.它有:1关系,其中提供者可以有许多项目,但每个项目只能有一个提供者.
到目前为止,我有这些关系:
class Provider extends CActiveRecord
{
...
public function relations()
{
return array(
'items' => array(self::HAS_MANY, 'Item', 'id_provider', 'order'=>'rank DESC'),
);
}
...
}
class Item extends CActiveRecord
{
...
public function relations()
{
return array(
'provider' => array(self::BELONGS_TO, 'Provider', 'id_provider'),
);
}
...
}
Run Code Online (Sandbox Code Playgroud)
在我的项目模型中,我已经有了一个defaultScope来过滤掉所有离线项目(即只显示设置为的项目offline = false):
public function defaultScope()
{
$alias = $this->getTableAlias(false,false);
return array(
'condition'=>"`$alias`.`offline` = false",
);
}
Run Code Online (Sandbox Code Playgroud)
我现在要做的是,还过滤掉其提供者设置为离线的项目(即仅显示provider.offline = false当前项目旁边的项目item.offline …
以下javascript代码允许您访问全局对象(window/worker).
(new function Outer(){
console.log(this); /* The object */
(function(){ // This function could be a 3rd Party function
console.log(this); /* window !!*/
})();
});
Run Code Online (Sandbox Code Playgroud)
有没有办法可以确保内部总是能够引用外部的上下文.
我知道我能做到
(new function Outer(){
'use strict';
console.log(this); /* The object */
(function(){ // This function could be a 3rd Party function
console.log(this); /* undefined ? !!*/
})();
});
Run Code Online (Sandbox Code Playgroud)
但这导致this未定义.
编辑
我知道bind,但如果内部函数是嵌套的.比如说像
(function(){
(function(){
(function(){
console.log(this);// undefined
})();
})();
}).bind(this)();
Run Code Online (Sandbox Code Playgroud)
我想要的是:外{}而不是使用变量引用外部: - |
来自Sitepoint的r937非常友好,可以帮助我找出从数据库返回正确结果所需的查询.
我需要的是能够将此查询用作范围,并能够将其他范围链接到此范围.
查询是:
SELECT coasters.*
FROM (
SELECT order_ridden,
MAX(version) AS max_version
FROM coasters
GROUP BY order_ridden
) AS m
INNER JOIN coasters
ON coasters.order_ridden = m.order_ridden
AND COALESCE(coasters.version,0) = COALESCE(m.max_version,0)
Run Code Online (Sandbox Code Playgroud)
我尝试制作这样的范围:
scope :uniques, lambda {
find_by_sql('SELECT coasters.*
FROM (
SELECT order_ridden,
MAX(version) AS max_version
FROM coasters
GROUP BY order_ridden
) AS m
INNER JOIN coasters
ON coasters.order_ridden = m.order_ridden
AND COALESCE(coasters.version,0) = COALESCE(m.max_version,0)')
}
Run Code Online (Sandbox Code Playgroud)
但当我尝试将另一个示波器链接到它上面时,它失败了.有没有办法像普通范围一样运行此查询?
我正在尝试使用Spring引导SSO + Zuul创建一个简单的API网关.我需要将OAuth范围转换为标头,这些标头将被其他后端服务进一步用于基于标头进行RBAC.
我正在使用这个CustomOAuth2TokenRelayFilter,它基本上会在发送到后端之前设置标头.我的问题是如何从当前令牌获取范围.类OAuth2AuthenticationDetails确实提供了令牌值,但它不提供范围.
我不确定如何获得那里的范围.
以下是Custom Zuul过滤器,主要取自 https://github.com/spring-cloud/spring-cloud-security/blob/master/spring-cloud-security/src/main/java/org/springframework/cloud /security/oauth2/proxy/OAuth2TokenRelayFilter.java
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.OAuth2RestOperations;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.stereotype.Component;
@Component
public class CustomOAuth2TokenRelayFilter extends ZuulFilter {
private static Logger LOGGER = LoggerFactory.getLogger(CustomOAuth2TokenRelayFilter.class);
private static final String ACCESS_TOKEN = "ACCESS_TOKEN";
private static final String TOKEN_TYPE = "TOKEN_TYPE";
private OAuth2RestOperations restTemplate;
public void setRestTemplate(OAuth2RestOperations restTemplate) {
this.restTemplate = restTemplate;
}
@Override
public int filterOrder() {
return 1;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 根据Google People API的文档,我正在使用配置文件范围 - https://www.googleapis.com/auth/user.phonenumbers.read和PersonFields=phoneNumbers仅在其 Google 配置文件中读取经过身份验证的用户的电话号码(没有来自联系人列表)。我正在使用 API 密钥和 oAuth 访问令牌来授权请求。google people API 不会单独获取与上述范围的个人资料关联的电话号码。除了上述范围之外,还添加了整个联系人列表读取权限的范围,即www.googleapis.com/auth/contacts.readonly正确返回个人资料中的电话号码. 有没有办法从他/她的个人资料中获取用户的电话号码仅使用 user.phonenumbers.read 范围?
我正在构建一个应用程序,我将应用程序数据存储在 Google Drive 上的应用程序特定文件夹中。我已经能够设置与文件存储和检索相关的所有内容。我面临的问题是关于权限。用户可以选择从 Google Drive 设置面板断开应用程序。
我使用DriveScopes.DRIVE_APPDATA含义https://www.googleapis.com/auth/drive.appdata范围来保存数据。
我试图弄清楚如何找出这是否发生在应用程序端。如果我尝试继续使用与驱动器相关的 api,应用程序被断开连接,那么它会崩溃并显示UserRecoverableAuthException.
com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:297)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:476)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:409)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:526)
at abhiank.maplocs.ui.drivesync.DriveSyncService.onHandleIntent(DriveSyncService.kt:68)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
at com.google.android.gms.auth.zze.zzb(Unknown Source:13)
at com.google.android.gms.auth.zzd.zza(Unknown Source:77)
at com.google.android.gms.auth.zzd.zzb(Unknown Source:20)
at com.google.android.gms.auth.zzd.getToken(Unknown Source:7)
at com.google.android.gms.auth.zzd.getToken(Unknown Source:5)
at com.google.android.gms.auth.zzd.getToken(Unknown Source:2)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source:55)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:267)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:292)
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法来确定应用程序是否没有权限或范围。
GoogleSignInAccount从GoogleSignIn.getLastSignedInAccount(this). account.grantedScopes()在应用程序断开连接后,它具有以下可用范围。drive.appdata即使应用程序已断开连接也会显示。[https://www.googleapis.com/auth/drive.appdata, https://www.googleapis.com/auth/userinfo.profile, https://www.googleapis.com/auth/userinfo.email, openid, …Run Code Online (Sandbox Code Playgroud) 我正在尝试配置 KeyCloak 浏览器流程以允许请求scope1使用用户/密码表单的用户以及请求scope2使用用户/密码表单和 OTP 的用户。我的问题分为两部分:
我不想以用户为条件,而是以所请求的范围为条件。据我所知,为了完成这项工作,我需要实现一个自定义ConditionalAuthenticator,然后大致像这样配置,Condition - User Configured用我自己的实现替换。
主要问题:
我有两个 Google 电子表格:一个模板和一个母版。
该模板被发送给人们进行复制、填写,然后我有一个脚本将他们的选项卡复制到主电子表格中。
目前的授权非常广泛——查看、编辑、删除所有用户的电子表格。由于只涉及两个文件,我想将范围缩小到仅这两个文件,主要是因为授权过程现在对用户来说看起来很粗略。
有没有办法将范围限制为特定电子表格与所有电子表格?
到目前为止我发现/研究的内容:
似乎您可以轻松地将范围限制为当前文件,或要求访问所有电子表格。
我找到了两种方法:
1) 仅当前将此添加到脚本顶部:
/** * @OnlyCurrentDoc */ 这意味着我无法将选项卡复制到主电子表格。
2)设置显式范围进入清单,如下所述: https: //developers.google.com/apps-script/concepts/scopes 似乎这也只允许仅当前文件或完整电子表格访问。
类似问题:
其他人也提出了类似的问题,但还没有得到这个特定问题的答案,其中存在多个特定文件。
从自己的驱动器访问文件时如何使用更窄的 Google Apps 脚本授权范围
代码和潜在想法:
我还没有尝试过白名单 - 这有帮助吗?我会将模板上的主电子表格列入白名单吗?
我尝试“@OnlyCurrentDoc”时的授权将权限定义为“查看和管理已安装此应用程序的电子表格”。我可以在我的主电子表格中安装此应用程序并让他们交谈吗?有任何想法吗?
//这几乎是唯一适用的代码:
var admin_ss = SpreadsheetApp.openById([ID]);
var this_ss = SpreadsheetApp.getActiveSpreadsheet();
Run Code Online (Sandbox Code Playgroud) 在大多数 OAuth2 典型用例中,范围由需要用户登录的资源所有者密码授予类型或授权代码流使用。
看来scope主要是用来控制用户资源的访问的。例如,授权第3方客户端访问另一台服务器上的资源所有者(用户)资源。
在某些情况下,用户不在场。例如,一家公司只想为另一家公司提供API。正在使用客户端凭据。大多数 API 网关产品都有订阅者管理选项来控制哪个客户端 ID 可以访问哪些 API。在这种情况下,使用 OAuth 范围来管理对 API 的访问仍然有意义吗?为什么?
此外,我找不到任何使用范围和客户端凭据授予类型的示例。这是罕见的用例吗?
scopes ×10
google-oauth ×2
oauth-2.0 ×2
activerecord ×1
android ×1
chaining ×1
datetime ×1
google-api ×1
javascript ×1
keycloak ×1
oauth ×1
permissions ×1
relation ×1
roles ×1
ruby ×1
spring-boot ×1
sql ×1
yii ×1