Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6d76f14f
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 搜索 >>
提交
6d76f14f
编写于
4月 15, 2016
作者:
T
Timothy Andrew
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow revoking personal access tokens.
上级
e2a4051c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
48 addition
and
4 deletion
+48
-4
app/assets/stylesheets/pages/profile.scss
app/assets/stylesheets/pages/profile.scss
+3
-0
app/controllers/profiles/personal_access_tokens_controller.rb
...controllers/profiles/personal_access_tokens_controller.rb
+15
-1
app/models/personal_access_token.rb
app/models/personal_access_token.rb
+7
-0
app/views/profiles/personal_access_tokens/index.html.haml
app/views/profiles/personal_access_tokens/index.html.haml
+8
-1
config/locales/en.yml
config/locales/en.yml
+4
-0
config/routes.rb
config/routes.rb
+5
-1
db/migrate/20160415144643_add_column_revoked_to_personal_access_tokens.rb
...415144643_add_column_revoked_to_personal_access_tokens.rb
+5
-0
lib/api/helpers/authentication.rb
lib/api/helpers/authentication.rb
+1
-1
未找到文件。
app/assets/stylesheets/pages/profile.scss
浏览文件 @
6d76f14f
...
...
@@ -205,3 +205,6 @@
text-align
:
center
;
}
}
.personal-access-tokens-revoked-label
{
color
:
#bbb
;
}
\ No newline at end of file
app/controllers/profiles/personal_access_tokens_controller.rb
浏览文件 @
6d76f14f
class
Profiles::PersonalAccessTokensController
<
ApplicationController
def
index
@user
=
current_user
@personal_access_token
=
current_user
.
personal_access_tokens
.
new
# Prefer this to `@user.personal_access_tokens.new`, because it
# litters the view's call to `@user.personal_access_tokens` with
# this stub personal access token.
@personal_access_token
=
PersonalAccessToken
.
new
(
user:
@user
)
end
def
create
...
...
@@ -14,6 +18,16 @@ class Profiles::PersonalAccessTokensController < ApplicationController
end
end
def
revoke
@personal_access_token
=
current_user
.
personal_access_tokens
.
find
(
params
[
:id
])
if
@personal_access_token
.
revoke!
redirect_to
profile_personal_access_tokens_path
,
notice:
"Revoked personal access token
#{
@personal_access_token
.
name
}
!"
else
render
:index
end
end
private
def
personal_access_token_params
...
...
app/models/personal_access_token.rb
浏览文件 @
6d76f14f
class
PersonalAccessToken
<
ActiveRecord
::
Base
belongs_to
:user
scope
:active
,
->
{
where
.
not
(
revoked:
true
)
}
def
self
.
generate
(
params
)
personal_access_token
=
self
.
new
(
params
)
personal_access_token
.
token
=
Devise
.
friendly_token
(
50
)
personal_access_token
end
def
revoke!
self
.
revoked
=
true
self
.
save
end
end
app/views/profiles/personal_access_tokens/index.html.haml
浏览文件 @
6d76f14f
...
...
@@ -34,11 +34,18 @@
%th
Name
%th
Token
%th
Created At
%th
Actions
%tbody
-
@user
.
personal_access_tokens
.
each
do
|
token
|
-
@user
.
personal_access_tokens
.
order
(
:revoked
).
each
do
|
token
|
%tr
%td
=
token
.
name
%td
=
token
.
token
%td
=
token
.
created_at
-
if
token
.
revoked?
%td
%span
.personal-access-tokens-revoked-label
Revoked
-
else
%td
=
link_to
"Revoke"
,
revoke_profile_personal_access_token_path
(
token
),
method: :put
,
class:
"btn btn-danger"
,
data:
{
confirm:
t
(
'profile.personal_access_tokens.revoke.confirmation'
)}
-
else
%span
You don't have any tokens yet.
\ No newline at end of file
config/locales/en.yml
浏览文件 @
6d76f14f
...
...
@@ -12,3 +12,7 @@ en:
pagination
:
previous
:
"
Prev"
next
:
"
Next"
profile
:
personal_access_tokens
:
revoke
:
confirmation
:
"
Are
you
sure?
This
cannot
be
undone."
config/routes.rb
浏览文件 @
6d76f14f
...
...
@@ -333,7 +333,11 @@ Rails.application.routes.draw do
resources
:keys
resources
:emails
,
only:
[
:index
,
:create
,
:destroy
]
resource
:avatar
,
only:
[
:destroy
]
resources
:personal_access_tokens
,
only:
[
:index
,
:create
]
resources
:personal_access_tokens
,
only:
[
:index
,
:create
]
do
member
do
put
:revoke
end
end
resource
:two_factor_auth
,
only:
[
:new
,
:create
,
:destroy
]
do
member
do
post
:codes
...
...
db/migrate/20160415144643_add_column_revoked_to_personal_access_tokens.rb
0 → 100644
浏览文件 @
6d76f14f
class
AddColumnRevokedToPersonalAccessTokens
<
ActiveRecord
::
Migration
def
change
add_column
:personal_access_tokens
,
:revoked
,
:boolean
,
default:
false
end
end
lib/api/helpers/authentication.rb
浏览文件 @
6d76f14f
...
...
@@ -15,7 +15,7 @@ module API
def
find_user_by_personal_access_token
personal_access_token_string
=
(
params
[
PERSONAL_ACCESS_TOKEN_PARAM
]
||
env
[
PERSONAL_ACCESS_TOKEN_HEADER
]).
to_s
personal_access_token
=
PersonalAccessToken
.
find_by_token
(
personal_access_token_string
)
personal_access_token
=
PersonalAccessToken
.
active
.
find_by_token
(
personal_access_token_string
)
personal_access_token
.
user
if
personal_access_token
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录