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
91633281
Commit
91633281
authored
Nov 18, 2016
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop Project#authorized_for_user? in favor of ProjectTeam#member?
Closes #23938
parent
229b7e9a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
65 deletions
+61
-65
app/models/issue.rb
app/models/issue.rb
+1
-1
app/models/project.rb
app/models/project.rb
+0
-8
app/models/project_team.rb
app/models/project_team.rb
+6
-2
spec/helpers/members_helper_spec.rb
spec/helpers/members_helper_spec.rb
+2
-2
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-51
spec/models/project_team_spec.rb
spec/models/project_team_spec.rb
+51
-0
No files found.
app/models/issue.rb
View file @
91633281
...
...
@@ -93,7 +93,7 @@ class Issue < ActiveRecord::Base
# Check if we are scoped to a specific project's issues
if
owner_project
if
owner_project
.
authorized_for_us
er?
(
user
,
Gitlab
::
Access
::
REPORTER
)
if
owner_project
.
team
.
memb
er?
(
user
,
Gitlab
::
Access
::
REPORTER
)
# If the project is authorized for the user, they can see all issues in the project
return
all
else
...
...
app/models/project.rb
View file @
91633281
...
...
@@ -1293,14 +1293,6 @@ class Project < ActiveRecord::Base
end
end
# Checks if `user` is authorized for this project, with at least the
# `min_access_level` (if given).
def
authorized_for_user?
(
user
,
min_access_level
=
nil
)
return
false
unless
user
user
.
authorized_project?
(
self
,
min_access_level
)
end
def
append_or_update_attribute
(
name
,
value
)
old_values
=
public_send
(
name
.
to_s
)
...
...
app/models/project_team.rb
View file @
91633281
...
...
@@ -141,8 +141,12 @@ class ProjectTeam
max_member_access
(
user
.
id
)
==
Gitlab
::
Access
::
MASTER
end
def
member?
(
user
,
min_member_access
=
Gitlab
::
Access
::
GUEST
)
max_member_access
(
user
.
id
)
>=
min_member_access
# Checks if `user` is authorized for this project, with at least the
# `min_access_level` (if given).
def
member?
(
user
,
min_access_level
=
Gitlab
::
Access
::
GUEST
)
return
false
unless
user
user
.
authorized_project?
(
project
,
min_access_level
)
end
def
human_max_access
(
user_id
)
...
...
spec/helpers/members_helper_spec.rb
View file @
91633281
...
...
@@ -10,7 +10,7 @@ describe MembersHelper do
end
describe
'#remove_member_message'
do
let
(
:requester
)
{
build
(
:user
)
}
let
(
:requester
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
:access_requestable
)
}
let
(
:project_member
)
{
build
(
:project_member
,
project:
project
)
}
let
(
:project_member_invite
)
{
build
(
:project_member
,
project:
project
).
tap
{
|
m
|
m
.
generate_invite_token!
}
}
...
...
@@ -31,7 +31,7 @@ describe MembersHelper do
end
describe
'#remove_member_title'
do
let
(
:requester
)
{
build
(
:user
)
}
let
(
:requester
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
:access_requestable
)
}
let
(
:project_member
)
{
build
(
:project_member
,
project:
project
)
}
let
(
:project_member_request
)
{
project
.
request_access
(
requester
)
}
...
...
spec/models/issue_spec.rb
View file @
91633281
...
...
@@ -331,7 +331,7 @@ describe Issue, models: true do
end
context
'with a user'
do
let
(
:user
)
{
build
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:issue
)
{
build
(
:issue
)
}
it
'returns true when the issue is readable'
do
...
...
spec/models/project_spec.rb
View file @
91633281
...
...
@@ -1507,57 +1507,6 @@ describe Project, models: true do
end
end
describe
'authorized_for_user'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:developer
)
{
create
(
:user
)
}
let
(
:master
)
{
create
(
:user
)
}
let
(
:personal_project
)
{
create
(
:project
,
namespace:
developer
.
namespace
)
}
let
(
:group_project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:members_project
)
{
create
(
:project
)
}
let
(
:shared_project
)
{
create
(
:project
)
}
before
do
group
.
add_master
(
master
)
group
.
add_developer
(
developer
)
members_project
.
team
<<
[
developer
,
:developer
]
members_project
.
team
<<
[
master
,
:master
]
create
(
:project_group_link
,
project:
shared_project
,
group:
group
,
group_access:
Gitlab
::
Access
::
DEVELOPER
)
end
it
'returns false for no user'
do
expect
(
personal_project
.
authorized_for_user?
(
nil
)).
to
be
(
false
)
end
it
'returns true for personal projects of the user'
do
expect
(
personal_project
.
authorized_for_user?
(
developer
)).
to
be
(
true
)
end
it
'returns true for projects of groups the user is a member of'
do
expect
(
group_project
.
authorized_for_user?
(
developer
)).
to
be
(
true
)
end
it
'returns true for projects for which the user is a member of'
do
expect
(
members_project
.
authorized_for_user?
(
developer
)).
to
be
(
true
)
end
it
'returns true for projects shared on a group the user is a member of'
do
expect
(
shared_project
.
authorized_for_user?
(
developer
)).
to
be
(
true
)
end
it
'checks for the correct minimum level access'
do
expect
(
group_project
.
authorized_for_user?
(
developer
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
group_project
.
authorized_for_user?
(
master
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
true
)
expect
(
members_project
.
authorized_for_user?
(
developer
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
members_project
.
authorized_for_user?
(
master
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
true
)
expect
(
shared_project
.
authorized_for_user?
(
developer
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
shared_project
.
authorized_for_user?
(
master
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
shared_project
.
authorized_for_user?
(
developer
,
Gitlab
::
Access
::
DEVELOPER
)).
to
be
(
true
)
expect
(
shared_project
.
authorized_for_user?
(
master
,
Gitlab
::
Access
::
DEVELOPER
)).
to
be
(
true
)
end
end
describe
'change_head'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/project_team_spec.rb
View file @
91633281
...
...
@@ -261,6 +261,57 @@ describe ProjectTeam, models: true do
end
end
describe
'#member?'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:developer
)
{
create
(
:user
)
}
let
(
:master
)
{
create
(
:user
)
}
let
(
:personal_project
)
{
create
(
:project
,
namespace:
developer
.
namespace
)
}
let
(
:group_project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:members_project
)
{
create
(
:project
)
}
let
(
:shared_project
)
{
create
(
:project
)
}
before
do
group
.
add_master
(
master
)
group
.
add_developer
(
developer
)
members_project
.
team
<<
[
developer
,
:developer
]
members_project
.
team
<<
[
master
,
:master
]
create
(
:project_group_link
,
project:
shared_project
,
group:
group
)
end
it
'returns false for no user'
do
expect
(
personal_project
.
team
.
member?
(
nil
)).
to
be
(
false
)
end
it
'returns true for personal projects of the user'
do
expect
(
personal_project
.
team
.
member?
(
developer
)).
to
be
(
true
)
end
it
'returns true for projects of groups the user is a member of'
do
expect
(
group_project
.
team
.
member?
(
developer
)).
to
be
(
true
)
end
it
'returns true for projects for which the user is a member of'
do
expect
(
members_project
.
team
.
member?
(
developer
)).
to
be
(
true
)
end
it
'returns true for projects shared on a group the user is a member of'
do
expect
(
shared_project
.
team
.
member?
(
developer
)).
to
be
(
true
)
end
it
'checks for the correct minimum level access'
do
expect
(
group_project
.
team
.
member?
(
developer
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
group_project
.
team
.
member?
(
master
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
true
)
expect
(
members_project
.
team
.
member?
(
developer
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
members_project
.
team
.
member?
(
master
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
true
)
expect
(
shared_project
.
team
.
member?
(
developer
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
shared_project
.
team
.
member?
(
master
,
Gitlab
::
Access
::
MASTER
)).
to
be
(
false
)
expect
(
shared_project
.
team
.
member?
(
developer
,
Gitlab
::
Access
::
DEVELOPER
)).
to
be
(
true
)
expect
(
shared_project
.
team
.
member?
(
master
,
Gitlab
::
Access
::
DEVELOPER
)).
to
be
(
true
)
end
end
shared_examples_for
"#max_member_access_for_users"
do
|
enable_request_store
|
describe
"#max_member_access_for_users"
do
before
do
...
...
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