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
Léo-Paul Géneau
gitlab-ce
Commits
c31d48dd
Commit
c31d48dd
authored
Nov 25, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow project creation in scope of group for non-admin but group owners
parent
2f22874b
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
13 deletions
+62
-13
app/models/project.rb
app/models/project.rb
+12
-2
app/models/user.rb
app/models/user.rb
+1
-11
app/roles/account.rb
app/roles/account.rb
+35
-0
app/views/groups/people.html.haml
app/views/groups/people.html.haml
+2
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+10
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-0
No files found.
app/models/project.rb
View file @
c31d48dd
...
...
@@ -95,7 +95,6 @@ class Project < ActiveRecord::Base
def
create_by_user
(
params
,
user
)
namespace_id
=
params
.
delete
(
:namespace_id
)
namespace_id
||=
user
.
namespace
.
try
(
:id
)
project
=
Project
.
new
params
...
...
@@ -109,7 +108,18 @@ class Project < ActiveRecord::Base
project
.
path
=
project
.
name
.
dup
.
parameterize
project
.
owner
=
user
# Apply namespace if user has access to it
# else fallback to user namespace
project
.
namespace_id
=
user
.
namespace_id
if
namespace_id
group
=
Group
.
find_by_id
(
namespace_id
)
if
user
.
can?
:manage_group
,
group
project
.
namespace_id
=
namespace_id
end
end
project
.
save!
# Add user as project master
...
...
app/models/user.rb
View file @
c31d48dd
...
...
@@ -48,6 +48,7 @@ class User < ActiveRecord::Base
# Namespace for personal projects
has_one
:namespace
,
class_name:
"Namespace"
,
foreign_key: :owner_id
,
conditions:
'type IS NULL'
,
dependent: :destroy
has_many
:groups
,
class_name:
"Group"
,
foreign_key: :owner_id
has_many
:keys
,
dependent: :destroy
has_many
:projects
,
through: :users_projects
...
...
@@ -120,15 +121,4 @@ class User < ActiveRecord::Base
self
.
password
=
self
.
password_confirmation
=
Devise
.
friendly_token
.
first
(
8
)
end
end
def
namespaces
namespaces
=
[]
namespaces
<<
self
.
namespace
if
self
.
namespace
namespaces
=
namespaces
+
Group
.
all
if
admin
namespaces
end
def
several_namespaces?
namespaces
.
size
>
1
end
end
app/roles/account.rb
View file @
c31d48dd
...
...
@@ -26,6 +26,18 @@ module Account
is_admin?
end
def
abilities
@abilities
||=
begin
abilities
=
Six
.
new
abilities
<<
Ability
abilities
end
end
def
can?
action
,
subject
abilities
.
allowed?
(
self
,
action
,
subject
)
end
def
last_activity_project
projects
.
first
end
...
...
@@ -70,4 +82,27 @@ module Account
def
projects_sorted_by_activity
projects
.
order
(
"(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC"
)
end
def
namespaces
namespaces
=
[]
# Add user account namespace
namespaces
<<
self
.
namespace
if
self
.
namespace
# Add groups you can manage
namespaces
+=
if
admin
Group
.
all
else
groups
.
all
end
namespaces
end
def
several_namespaces?
namespaces
.
size
>
1
end
def
namespace_id
namespace
.
try
:id
end
end
app/views/groups/people.html.haml
View file @
c31d48dd
...
...
@@ -9,4 +9,6 @@
=
image_tag
gravatar_icon
(
user
.
email
,
16
),
class:
"avatar s16"
%strong
=
user
.
name
%span
.cgray
=
user
.
email
-
if
@group
.
owner
==
user
%span
.btn.btn-small.disabled.right
Owner
spec/models/namespace_spec.rb
View file @
c31d48dd
...
...
@@ -22,4 +22,14 @@ describe Namespace do
it
{
should
validate_presence_of
:path
}
it
{
should
validate_uniqueness_of
(
:path
)
}
it
{
should
validate_presence_of
:owner
}
describe
"Mass assignment"
do
it
{
should
allow_mass_assignment_of
(
:name
)
}
it
{
should
allow_mass_assignment_of
(
:path
)
}
end
describe
"Respond to"
do
it
{
should
respond_to
(
:human_name
)
}
it
{
should
respond_to
(
:to_param
)
}
end
end
spec/models/project_spec.rb
View file @
c31d48dd
...
...
@@ -40,6 +40,7 @@ describe Project do
end
describe
"Mass assignment"
do
it
{
should_not
allow_mass_assignment_of
(
:namespace_id
)
}
it
{
should_not
allow_mass_assignment_of
(
:owner_id
)
}
it
{
should_not
allow_mass_assignment_of
(
:private_flag
)
}
end
...
...
spec/models/user_spec.rb
View file @
c31d48dd
...
...
@@ -40,6 +40,7 @@ describe User do
it
{
should
have_one
(
:namespace
)
}
it
{
should
have_many
(
:users_projects
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:projects
)
}
it
{
should
have_many
(
:groups
)
}
it
{
should
have_many
(
:my_own_projects
).
class_name
(
'Project'
)
}
it
{
should
have_many
(
:keys
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:events
).
class_name
(
'Event'
).
dependent
(
:destroy
)
}
...
...
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