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
Jérome Perrin
gitlab-ce
Commits
81697850
Commit
81697850
authored
Jun 17, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create UsersGroup entity. Modify ability to check group owners instead one owner
parent
cc5440e8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
37 deletions
+85
-37
app/models/ability.rb
app/models/ability.rb
+1
-1
app/models/group.rb
app/models/group.rb
+6
-0
app/models/users_group.rb
app/models/users_group.rb
+21
-0
db/migrate/20130617095603_create_users_groups.rb
db/migrate/20130617095603_create_users_groups.rb
+11
-0
db/schema.rb
db/schema.rb
+32
-36
spec/factories/users_groups.rb
spec/factories/users_groups.rb
+9
-0
spec/models/users_group_spec.rb
spec/models/users_group_spec.rb
+5
-0
No files found.
app/models/ability.rb
View file @
81697850
...
@@ -132,7 +132,7 @@ class Ability
...
@@ -132,7 +132,7 @@ class Ability
rules
=
[]
rules
=
[]
# Only group owner and administrators can manage group
# Only group owner and administrators can manage group
if
group
.
owner
==
user
||
user
.
admin?
if
group
.
owner
s
.
include?
(
user
)
||
user
.
admin?
rules
<<
[
rules
<<
[
:manage_group
,
:manage_group
,
:manage_namespace
:manage_namespace
...
...
app/models/group.rb
View file @
81697850
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
#
#
class
Group
<
Namespace
class
Group
<
Namespace
has_many
:users_groups
,
dependent: :destroy
has_many
:users
,
through: :users_groups
def
add_users_to_project_teams
(
user_ids
,
project_access
)
def
add_users_to_project_teams
(
user_ids
,
project_access
)
UsersProject
.
add_users_into_projects
(
UsersProject
.
add_users_into_projects
(
...
@@ -35,4 +37,8 @@ class Group < Namespace
...
@@ -35,4 +37,8 @@ class Group < Namespace
def
truncate_teams
def
truncate_teams
UsersProject
.
truncate_teams
(
project_ids
)
UsersProject
.
truncate_teams
(
project_ids
)
end
end
def
owners
@owners
||=
(
users_groups
.
owners
.
map
(
&
:user
)
<<
owner
)
end
end
end
app/models/users_group.rb
0 → 100644
View file @
81697850
class
UsersGroup
<
ActiveRecord
::
Base
GUEST
=
10
REPORTER
=
20
DEVELOPER
=
30
MASTER
=
40
OWNER
=
50
attr_accessible
:group_access
,
:group_id
,
:user_id
belongs_to
:user
belongs_to
:project
scope
:guests
,
->
{
where
(
group_access:
GUEST
)
}
scope
:reporters
,
->
{
where
(
group_access:
REPORTER
)
}
scope
:developers
,
->
{
where
(
group_access:
DEVELOPER
)
}
scope
:masters
,
->
{
where
(
group_access:
MASTER
)
}
scope
:owners
,
->
{
where
(
group_access:
OWNER
)
}
scope
:with_group
,
->
(
group
)
{
where
(
group_id:
group
.
id
)
}
scope
:with_user
,
->
(
user
)
{
where
(
user_id:
user
.
id
)
}
end
db/migrate/20130617095603_create_users_groups.rb
0 → 100644
View file @
81697850
class
CreateUsersGroups
<
ActiveRecord
::
Migration
def
change
create_table
:users_groups
do
|
t
|
t
.
integer
:group_access
,
null:
false
t
.
integer
:group_id
,
null:
false
t
.
integer
:user_id
,
null:
false
t
.
timestamps
end
end
end
db/schema.rb
View file @
81697850
...
@@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
integer
"assignee_id"
t
.
integer
"assignee_id"
t
.
integer
"author_id"
t
.
integer
"author_id"
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
integer
"position"
,
:default
=>
0
t
.
integer
"position"
,
:default
=>
0
t
.
string
"branch_name"
t
.
string
"branch_name"
t
.
text
"description"
t
.
text
"description"
...
@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
create_table
"keys"
,
:force
=>
true
do
|
t
|
create_table
"keys"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
t
.
integer
"user_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
text
"key"
t
.
text
"key"
t
.
string
"title"
t
.
string
"title"
t
.
string
"identifier"
t
.
string
"identifier"
...
@@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
integer
"author_id"
t
.
integer
"author_id"
t
.
integer
"assignee_id"
t
.
integer
"assignee_id"
t
.
string
"title"
t
.
string
"title"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
text
"st_commits"
,
:limit
=>
2147483647
t
.
text
"st_commits"
,
:limit
=>
2147483647
t
.
text
"st_diffs"
,
:limit
=>
2147483647
t
.
text
"st_diffs"
,
:limit
=>
2147483647
t
.
integer
"milestone_id"
t
.
integer
"milestone_id"
...
@@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
text
"note"
t
.
text
"note"
t
.
string
"noteable_type"
t
.
string
"noteable_type"
t
.
integer
"author_id"
t
.
integer
"author_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
string
"attachment"
t
.
string
"attachment"
t
.
string
"line_code"
t
.
string
"line_code"
...
@@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
string
"name"
t
.
string
"name"
t
.
string
"path"
t
.
string
"path"
t
.
text
"description"
t
.
text
"description"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
integer
"creator_id"
t
.
integer
"creator_id"
t
.
string
"default_branch"
t
.
string
"default_branch"
t
.
boolean
"issues_enabled"
,
:default
=>
true
,
:null
=>
false
t
.
boolean
"issues_enabled"
,
:default
=>
true
,
:null
=>
false
...
@@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
text
"content"
t
.
text
"content"
t
.
integer
"author_id"
,
:null
=>
false
t
.
integer
"author_id"
,
:null
=>
false
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
string
"file_name"
t
.
string
"file_name"
t
.
datetime
"expires_at"
t
.
datetime
"expires_at"
t
.
boolean
"private"
,
:default
=>
true
,
:null
=>
false
t
.
boolean
"private"
,
:default
=>
true
,
:null
=>
false
...
@@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
datetime
"created_at"
t
.
datetime
"created_at"
end
end
add_index
"taggings"
,
[
"tag_id"
],
:name
=>
"index_taggings_on_tag_id"
add_index
"taggings"
,
[
"taggable_id"
,
"taggable_type"
,
"context"
],
:name
=>
"index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table
"tags"
,
:force
=>
true
do
|
t
|
create_table
"tags"
,
:force
=>
true
do
|
t
|
t
.
string
"name"
t
.
string
"name"
end
end
...
@@ -263,7 +260,7 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -263,7 +260,7 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
create_table
"users"
,
:force
=>
true
do
|
t
|
create_table
"users"
,
:force
=>
true
do
|
t
|
t
.
string
"email"
,
:default
=>
""
,
:null
=>
false
t
.
string
"email"
,
:default
=>
""
,
:null
=>
false
t
.
string
"encrypted_password"
,
:default
=>
""
,
:null
=>
false
t
.
string
"encrypted_password"
,
:
limit
=>
128
,
:
default
=>
""
,
:null
=>
false
t
.
string
"reset_password_token"
t
.
string
"reset_password_token"
t
.
datetime
"reset_password_sent_at"
t
.
datetime
"reset_password_sent_at"
t
.
datetime
"remember_created_at"
t
.
datetime
"remember_created_at"
...
@@ -272,8 +269,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -272,8 +269,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
t
.
datetime
"last_sign_in_at"
t
.
datetime
"last_sign_in_at"
t
.
string
"current_sign_in_ip"
t
.
string
"current_sign_in_ip"
t
.
string
"last_sign_in_ip"
t
.
string
"last_sign_in_ip"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
string
"name"
t
.
string
"name"
t
.
boolean
"admin"
,
:default
=>
false
,
:null
=>
false
t
.
boolean
"admin"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"projects_limit"
,
:default
=>
10
t
.
integer
"projects_limit"
,
:default
=>
10
...
@@ -299,7 +296,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -299,7 +296,6 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
add_index
"users"
,
[
"admin"
],
:name
=>
"index_users_on_admin"
add_index
"users"
,
[
"admin"
],
:name
=>
"index_users_on_admin"
add_index
"users"
,
[
"email"
],
:name
=>
"index_users_on_email"
,
:unique
=>
true
add_index
"users"
,
[
"email"
],
:name
=>
"index_users_on_email"
,
:unique
=>
true
add_index
"users"
,
[
"extern_uid"
,
"provider"
],
:name
=>
"index_users_on_extern_uid_and_provider"
,
:unique
=>
true
add_index
"users"
,
[
"name"
],
:name
=>
"index_users_on_name"
add_index
"users"
,
[
"name"
],
:name
=>
"index_users_on_name"
add_index
"users"
,
[
"reset_password_token"
],
:name
=>
"index_users_on_reset_password_token"
,
:unique
=>
true
add_index
"users"
,
[
"reset_password_token"
],
:name
=>
"index_users_on_reset_password_token"
,
:unique
=>
true
add_index
"users"
,
[
"username"
],
:name
=>
"index_users_on_username"
add_index
"users"
,
[
"username"
],
:name
=>
"index_users_on_username"
...
@@ -307,8 +303,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -307,8 +303,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
create_table
"users_projects"
,
:force
=>
true
do
|
t
|
create_table
"users_projects"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
integer
"project_access"
,
:default
=>
0
,
:null
=>
false
t
.
integer
"project_access"
,
:default
=>
0
,
:null
=>
false
t
.
integer
"notification_level"
,
:default
=>
3
,
:null
=>
false
t
.
integer
"notification_level"
,
:default
=>
3
,
:null
=>
false
end
end
...
@@ -320,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
...
@@ -320,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20130614132337) do
create_table
"web_hooks"
,
:force
=>
true
do
|
t
|
create_table
"web_hooks"
,
:force
=>
true
do
|
t
|
t
.
string
"url"
t
.
string
"url"
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
string
"type"
,
:default
=>
"ProjectHook"
t
.
string
"type"
,
:default
=>
"ProjectHook"
t
.
integer
"service_id"
t
.
integer
"service_id"
end
end
...
...
spec/factories/users_groups.rb
0 → 100644
View file @
81697850
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl
.
define
do
factory
:users_group
do
access_level
1
group_id
1
user_id
1
end
end
spec/models/users_group_spec.rb
0 → 100644
View file @
81697850
require
'spec_helper'
describe
UsersGroup
do
pending
"add some examples to (or delete)
#{
__FILE__
}
"
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