Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
364791c9
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
364791c9
编写于
3月 08, 2019
作者:
L
Lin Jen-Shin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update TokenAuthenticatable so methods can be overridden
上级
6b0d4933
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
8 deletion
+19
-8
app/models/application_setting.rb
app/models/application_setting.rb
+6
-2
app/models/concerns/token_authenticatable.rb
app/models/concerns/token_authenticatable.rb
+13
-6
未找到文件。
app/models/application_setting.rb
浏览文件 @
364791c9
...
...
@@ -7,11 +7,15 @@ class ApplicationSetting < ActiveRecord::Base
include
IgnorableColumn
include
ChronicDurationAttribute
include
ApplicationSettingImplementation
add_authentication_token_field
:runners_registration_token
,
encrypted:
->
{
Feature
.
enabled?
(
:application_settings_tokens_optional_encryption
)
?
:optional
:
:required
}
add_authentication_token_field
:health_check_access_token
# Include here so it can override methods from
# `add_authentication_token_field`
# We don't prepend for now because otherwise we'll need to
# fix a lot of tests using allow_any_instance_of
include
ApplicationSettingImplementation
serialize
:restricted_visibility_levels
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:import_sources
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:disabled_oauth_sign_in_sources
,
Array
# rubocop:disable Cop/ActiveRecordSerialize
...
...
app/models/concerns/token_authenticatable.rb
浏览文件 @
364791c9
...
...
@@ -26,34 +26,41 @@ module TokenAuthenticatable
end
end
define_method
(
token_field
)
do
mod
=
token_authenticatable_module
mod
.
define_method
(
token_field
)
do
strategy
.
get_token
(
self
)
end
define_method
(
"set_
#{
token_field
}
"
)
do
|
token
|
mod
.
define_method
(
"set_
#{
token_field
}
"
)
do
|
token
|
strategy
.
set_token
(
self
,
token
)
end
define_method
(
"ensure_
#{
token_field
}
"
)
do
mod
.
define_method
(
"ensure_
#{
token_field
}
"
)
do
strategy
.
ensure_token
(
self
)
end
# Returns a token, but only saves when the database is in read & write mode
define_method
(
"ensure_
#{
token_field
}
!"
)
do
mod
.
define_method
(
"ensure_
#{
token_field
}
!"
)
do
strategy
.
ensure_token!
(
self
)
end
# Resets the token, but only saves when the database is in read & write mode
define_method
(
"reset_
#{
token_field
}
!"
)
do
mod
.
define_method
(
"reset_
#{
token_field
}
!"
)
do
strategy
.
reset_token!
(
self
)
end
define_method
(
"
#{
token_field
}
_matches?"
)
do
|
other_token
|
mod
.
define_method
(
"
#{
token_field
}
_matches?"
)
do
|
other_token
|
token
=
read_attribute
(
token_field
)
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
other_token
,
token
)
end
end
def
token_authenticatable_module
@token_authenticatable_module
||=
const_set
(
:TokenAuthenticatable
,
Module
.
new
).
tap
(
&
method
(
:include
))
end
def
token_authenticatable_fields
@token_authenticatable_fields
||=
[]
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录