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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
02732e85
Commit
02732e85
authored
Jul 24, 2018
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce PolicyCheckable for checking policies
parent
8f693d3c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
17 deletions
+52
-17
app/models/deploy_token.rb
app/models/deploy_token.rb
+1
-6
app/policies/base_policy.rb
app/policies/base_policy.rb
+0
-10
app/policies/concerns/policy_checkable.rb
app/policies/concerns/policy_checkable.rb
+38
-0
config/application.rb
config/application.rb
+1
-0
ee/app/policies/ee/base_policy.rb
ee/app/policies/ee/base_policy.rb
+9
-0
ee/app/policies/ee/policy_checkable.rb
ee/app/policies/ee/policy_checkable.rb
+3
-1
No files found.
app/models/deploy_token.rb
View file @
02732e85
class
DeployToken
<
ActiveRecord
::
Base
include
Expirable
include
TokenAuthenticatable
include
PolicyCheckable
add_authentication_token_field
:token
prepend
EE
::
DeployToken
AVAILABLE_SCOPES
=
%i(read_repository read_registry)
.
freeze
GITLAB_DEPLOY_TOKEN_NAME
=
'gitlab-deploy-token'
.
freeze
...
...
@@ -60,10 +59,6 @@ class DeployToken < ActiveRecord::Base
write_attribute
(
:expires_at
,
value
.
presence
||
Forever
.
date
)
end
def
admin?
false
end
private
def
ensure_at_least_one_scope
...
...
app/policies/base_policy.rb
View file @
02732e85
...
...
@@ -22,14 +22,4 @@ class BasePolicy < DeclarativePolicy::Base
# This is prevented in some cases in `gitlab-ee`
rule
{
default
}.
enable
:read_cross_project
# EE Extensions
with_scope
:user
condition
(
:auditor
,
score:
0
)
{
@user
&
.
auditor?
}
with_scope
:user
condition
(
:support_bot
,
score:
0
)
{
@user
&
.
support_bot?
}
with_scope
:global
condition
(
:license_block
)
{
License
.
block_changes?
}
end
app/policies/concerns/policy_checkable.rb
0 → 100644
View file @
02732e85
# frozen_string_literal: true
# Include this module if we want to pass something else than the user to
# check policies. This defines several methods which the policy checker
# would call and check.
module
PolicyCheckable
extend
ActiveSupport
::
Concern
prepend
EE
::
PolicyCheckable
def
blocked?
false
end
def
admin?
false
end
def
external?
false
end
def
internal?
false
end
def
access_locked?
false
end
def
required_terms_not_accepted?
false
end
def
can_create_group
false
end
end
config/application.rb
View file @
02732e85
...
...
@@ -45,6 +45,7 @@ module Gitlab
#{
config
.
root
}
/app/models/members
#{
config
.
root
}
/app/models/project_services
#{
config
.
root
}
/app/workers/concerns
#{
config
.
root
}
/app/policies/concerns
#{
config
.
root
}
/app/services/concerns
#{
config
.
root
}
/app/serializers/concerns
#{
config
.
root
}
/app/finders/concerns
...
...
ee/app/policies/ee/base_policy.rb
View file @
02732e85
...
...
@@ -10,6 +10,15 @@ module EE
rule
{
external_authorization_enabled
&
~
admin
&
~
auditor
}.
policy
do
prevent
:read_cross_project
end
with_scope
:user
condition
(
:auditor
,
score:
0
)
{
@user
&
.
auditor?
}
with_scope
:user
condition
(
:support_bot
,
score:
0
)
{
@user
&
.
support_bot?
}
with_scope
:global
condition
(
:license_block
)
{
License
.
block_changes?
}
end
end
end
ee/app/
models/ee/deploy_token
.rb
→
ee/app/
policies/ee/policy_checkable
.rb
View file @
02732e85
# frozen_string_literal: true
module
EE
module
DeployToken
module
PolicyCheckable
def
auditor?
false
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