Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
55fe0d7d
Commit
55fe0d7d
authored
Oct 03, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set default scope on PATs that don't have one set to allow them to be revoked
parent
b8e47d72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
3 deletions
+14
-3
app/controllers/profiles/personal_access_tokens_controller.rb
...controllers/profiles/personal_access_tokens_controller.rb
+1
-1
app/models/personal_access_token.rb
app/models/personal_access_token.rb
+6
-0
app/views/shared/_personal_access_tokens_form.html.haml
app/views/shared/_personal_access_tokens_form.html.haml
+2
-2
changelogs/unreleased/dm-pat-revoke.yml
changelogs/unreleased/dm-pat-revoke.yml
+5
-0
No files found.
app/controllers/profiles/personal_access_tokens_controller.rb
View file @
55fe0d7d
class
Profiles::PersonalAccessTokensController
<
Profiles
::
ApplicationController
class
Profiles::PersonalAccessTokensController
<
Profiles
::
ApplicationController
def
index
def
index
set_index_vars
set_index_vars
@personal_access_token
=
finder
.
build
end
end
def
create
def
create
...
@@ -40,7 +41,6 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
...
@@ -40,7 +41,6 @@ class Profiles::PersonalAccessTokensController < Profiles::ApplicationController
def
set_index_vars
def
set_index_vars
@scopes
=
Gitlab
::
Auth
.
available_scopes
@scopes
=
Gitlab
::
Auth
.
available_scopes
@personal_access_token
=
finder
.
build
@inactive_personal_access_tokens
=
finder
(
state:
'inactive'
).
execute
@inactive_personal_access_tokens
=
finder
(
state:
'inactive'
).
execute
@active_personal_access_tokens
=
finder
(
state:
'active'
).
execute
.
order
(
:expires_at
)
@active_personal_access_tokens
=
finder
(
state:
'active'
).
execute
.
order
(
:expires_at
)
end
end
...
...
app/models/personal_access_token.rb
View file @
55fe0d7d
...
@@ -17,6 +17,8 @@ class PersonalAccessToken < ActiveRecord::Base
...
@@ -17,6 +17,8 @@ class PersonalAccessToken < ActiveRecord::Base
validates
:scopes
,
presence:
true
validates
:scopes
,
presence:
true
validate
:validate_scopes
validate
:validate_scopes
after_initialize
:set_default_scopes
,
if: :persisted?
def
revoke!
def
revoke!
update!
(
revoked:
true
)
update!
(
revoked:
true
)
end
end
...
@@ -32,4 +34,8 @@ class PersonalAccessToken < ActiveRecord::Base
...
@@ -32,4 +34,8 @@ class PersonalAccessToken < ActiveRecord::Base
errors
.
add
:scopes
,
"can only contain available scopes"
errors
.
add
:scopes
,
"can only contain available scopes"
end
end
end
end
def
set_default_scopes
self
.
scopes
=
Gitlab
::
Auth
::
DEFAULT_SCOPES
if
self
.
scopes
.
empty?
end
end
end
app/views/shared/_personal_access_tokens_form.html.haml
View file @
55fe0d7d
-
type
=
impersonation
?
"impersonation"
:
"personal access"
-
type
=
impersonation
?
"impersonation"
:
"personal access"
%h5
.prepend-top-0
%h5
.prepend-top-0
Add a
#{
type
}
T
oken
Add a
#{
type
}
t
oken
%p
.profile-settings-content
%p
.profile-settings-content
Pick a name for the application, and we'll give you a unique
#{
type
}
T
oken.
Pick a name for the application, and we'll give you a unique
#{
type
}
t
oken.
=
form_for
token
,
url:
path
,
method: :post
,
html:
{
class:
'js-requires-input'
}
do
|
f
|
=
form_for
token
,
url:
path
,
method: :post
,
html:
{
class:
'js-requires-input'
}
do
|
f
|
...
...
changelogs/unreleased/dm-pat-revoke.yml
0 → 100644
View file @
55fe0d7d
---
title
:
Set default scope on PATs that don't have one set to allow them to be revoked
merge_request
:
author
:
type
:
fixed
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment