Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
de2ba7e7826a
Commit
de2ba7e7
authored
Mar 11, 2016
by
Dmitriy Zaporozhets
Browse files
Bring ProjectGroupLink model and migrations from EE
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
93f91f891195
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/models/group.rb
View file @
de2ba7e7
...
...
@@ -23,6 +23,8 @@
has_many
:group_members
,
dependent: :destroy
,
as: :source
,
class_name:
'GroupMember'
alias_method
:members
,
:group_members
has_many
:users
,
through: :group_members
has_many
:project_group_links
,
dependent: :destroy
has_many
:shared_projects
,
through: :project_group_links
,
source: :project
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
...
...
app/models/project.rb
View file @
de2ba7e7
...
...
@@ -151,6 +151,8 @@
has_many
:releases
,
dependent: :destroy
has_many
:lfs_objects_projects
,
dependent: :destroy
has_many
:lfs_objects
,
through: :lfs_objects_projects
has_many
:project_group_links
,
dependent: :destroy
has_many
:invited_groups
,
through: :project_group_links
,
source: :group
has_many
:todos
,
dependent: :destroy
has_one
:import_data
,
dependent: :destroy
,
class_name:
"ProjectImportData"
...
...
app/models/project_group_link.rb
0 → 100644
View file @
de2ba7e7
class
ProjectGroupLink
<
ActiveRecord
::
Base
GUEST
=
10
REPORTER
=
20
DEVELOPER
=
30
MASTER
=
40
belongs_to
:project
belongs_to
:group
validates
:project_id
,
presence:
true
validates
:group_id
,
presence:
true
validates
:group_id
,
uniqueness:
{
scope:
[
:project_id
],
message:
"already shared with this group"
}
validates
:group_access
,
presence:
true
validates
:group_access
,
inclusion:
{
in:
Gitlab
::
Access
.
values
},
presence:
true
validate
:different_group
def
self
.
access_options
Gitlab
::
Access
.
options
end
def
self
.
default_access
DEVELOPER
end
def
human_access
self
.
class
.
access_options
.
key
(
self
.
group_access
)
end
private
def
different_group
if
self
.
group
&&
self
.
project
&&
self
.
project
.
group
==
self
.
group
errors
.
add
(
:base
,
"Project cannot be shared with the project it is in."
)
end
end
end
db/migrate/20130711063759_create_project_group_links.rb
0 → 100644
View file @
de2ba7e7
class
CreateProjectGroupLinks
<
ActiveRecord
::
Migration
def
change
create_table
:project_group_links
do
|
t
|
t
.
integer
:project_id
,
null:
false
t
.
integer
:group_id
,
null:
false
t
.
timestamps
end
end
end
db/migrate/20130820102832_add_access_to_project_group_link.rb
0 → 100644
View file @
de2ba7e7
class
AddAccessToProjectGroupLink
<
ActiveRecord
::
Migration
def
change
add_column
:project_group_links
,
:group_access
,
:integer
,
null:
false
,
default:
ProjectGroupLink
.
default_access
end
end
db/schema.rb
View file @
de2ba7e7
...
...
@@ -656,6 +656,14 @@
add_index
"oauth_applications"
,
[
"owner_id"
,
"owner_type"
],
name:
"index_oauth_applications_on_owner_id_and_owner_type"
,
using: :btree
add_index
"oauth_applications"
,
[
"uid"
],
name:
"index_oauth_applications_on_uid"
,
unique:
true
,
using: :btree
create_table
"project_group_links"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
integer
"group_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
integer
"group_access"
,
default:
30
,
null:
false
end
create_table
"project_import_data"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
t
.
text
"data"
...
...
@@ -749,9 +757,9 @@
t
.
string
"type"
t
.
string
"title"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
boolean
"active"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
boolean
"active"
,
default:
false
,
null:
false
t
.
text
"properties"
t
.
boolean
"template"
,
default:
false
t
.
boolean
"push_events"
,
default:
true
...
...
spec/factories/project_group_links.rb
0 → 100644
View file @
de2ba7e7
FactoryGirl
.
define
do
factory
:project_group_link
do
project
group
end
end
spec/models/project_group_link_spec.rb
0 → 100644
View file @
de2ba7e7
require
'spec_helper'
describe
ProjectGroupLink
do
describe
"Associations"
do
it
{
should
belong_to
(
:group
)
}
it
{
should
belong_to
(
:project
)
}
end
describe
"Validation"
do
let!
(
:project_group_link
)
{
create
(
:project_group_link
)
}
it
{
should
validate_presence_of
(
:project_id
)
}
it
{
should
validate_uniqueness_of
(
:group_id
).
scoped_to
(
:project_id
).
with_message
(
/already shared/
)
}
it
{
should
validate_presence_of
(
:group_id
)
}
it
{
should
validate_presence_of
(
:group_access
)
}
end
end
Write
Preview
Supports
Markdown
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