Bring ProjectGroupLink model and migrations from EE
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
29ac9f64ea
commit
ea5f4cae53
8 changed files with 89 additions and 3 deletions
|
@ -23,6 +23,8 @@ class Group < Namespace
|
|||
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 }
|
||||
|
|
|
@ -151,6 +151,8 @@ class Project < ActiveRecord::Base
|
|||
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"
|
||||
|
|
36
app/models/project_group_link.rb
Normal file
36
app/models/project_group_link.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
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
|
10
db/migrate/20130711063759_create_project_group_links.rb
Normal file
10
db/migrate/20130711063759_create_project_group_links.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
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
|
|
@ -0,0 +1,5 @@
|
|||
class AddAccessToProjectGroupLink < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :project_group_links, :group_access, :integer, null: false, default: ProjectGroupLink.default_access
|
||||
end
|
||||
end
|
14
db/schema.rb
14
db/schema.rb
|
@ -656,6 +656,14 @@ ActiveRecord::Schema.define(version: 20160309140734) do
|
|||
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 @@ ActiveRecord::Schema.define(version: 20160309140734) do
|
|||
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
|
||||
|
|
6
spec/factories/project_group_links.rb
Normal file
6
spec/factories/project_group_links.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :project_group_link do
|
||||
project
|
||||
group
|
||||
end
|
||||
end
|
17
spec/models/project_group_link_spec.rb
Normal file
17
spec/models/project_group_link_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
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
|
Loading…
Reference in a new issue