BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
1d0ccec6
Commit
1d0ccec6
authored
Nov 22, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a `scopes` column to the `personal_access_tokens` table
parent
49a70d1e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
0 deletions
+79
-0
personal_access_token.rb
app/models/personal_access_token.rb
+2
-0
20160823083941_add_column_scopes_to_personal_access_tokens.rb
...0823083941_add_column_scopes_to_personal_access_tokens.rb
+36
-0
20160824121037_change_personal_access_tokens_default_back_to_empty_array.rb
...nge_personal_access_tokens_default_back_to_empty_array.rb
+39
-0
schema.rb
db/schema.rb
+1
-0
personal_access_tokens.rb
spec/factories/personal_access_tokens.rb
+1
-0
No files found.
app/models/personal_access_token.rb
View file @
1d0ccec6
...
...
@@ -2,6 +2,8 @@ class PersonalAccessToken < ActiveRecord::Base
include
TokenAuthenticatable
add_authentication_token_field
:token
serialize
:scopes
,
Array
belongs_to
:user
scope
:active
,
->
{
where
(
revoked:
false
).
where
(
"expires_at >= NOW() OR expires_at IS NULL"
)
}
...
...
db/migrate/20160823083941_add_column_scopes_to_personal_access_tokens.rb
0 → 100644
View file @
1d0ccec6
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddColumnScopesToPersonalAccessTokens
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method is the _only_ method called in the migration, any other changes
# should go in a separate migration. This ensures that upon failure _only_ the
# index creation fails and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
disable_ddl_transaction!
def
up
# The default needs to be `[]`, but all existing access tokens need to have `scopes` set to `['api']`.
# It's easier to achieve this by adding the column with the `['api']` default, and then changing the default to
# `[]`.
add_column_with_default
:personal_access_tokens
,
:scopes
,
:string
,
default:
[
'api'
].
to_yaml
end
def
down
remove_column
:personal_access_tokens
,
:scopes
end
end
db/migrate/20160824121037_change_personal_access_tokens_default_back_to_empty_array.rb
0 → 100644
View file @
1d0ccec6
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
ChangePersonalAccessTokensDefaultBackToEmptyArray
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method is the _only_ method called in the migration, any other changes
# should go in a separate migration. This ensures that upon failure _only_ the
# index creation fails and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def
up
# The default needs to be `[]`, but all existing access tokens need to have `scopes` set to `['api']`.
# It's easier to achieve this by adding the column with the `['api']` default, and then changing the default to
# `[]`.
change_column_default
:personal_access_tokens
,
:scopes
,
[].
to_yaml
end
def
down
# The default needs to be `[]`, but all existing access tokens need to have `scopes` set to `['api']`.
# It's easier to achieve this by adding the column with the `['api']` default, and then changing the default to
# `[]`.
change_column_default
:personal_access_tokens
,
:scopes
,
[
'api'
].
to_yaml
end
end
db/schema.rb
View file @
1d0ccec6
...
...
@@ -854,6 +854,7 @@ ActiveRecord::Schema.define(version: 20161212142807) do
t
.
datetime
"expires_at"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
string
"scopes"
,
default:
"--- []
\n
"
,
null:
false
end
add_index
"personal_access_tokens"
,
[
"token"
],
name:
"index_personal_access_tokens_on_token"
,
unique:
true
,
using: :btree
...
...
spec/factories/personal_access_tokens.rb
View file @
1d0ccec6
...
...
@@ -5,5 +5,6 @@ FactoryGirl.define do
name
{
FFaker
::
Product
.
brand
}
revoked
false
expires_at
{
5
.
days
.
from_now
}
scopes
[
'api'
]
end
end
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