Commit ed680349 authored by Douwe Maan's avatar Douwe Maan

Don't allow project to be shared with the group it is already in.

parent fa9da48b
......@@ -5,6 +5,7 @@ v 7.9.0 (unreleased)
- Use one custom header logo for all GitLab themes in appearance settings
- Escape wildcards when searching LDAP by group name.
- Group level Web Hooks
- Don't allow project to be shared with the group it is already in.
v 7.8.0
- Improved Jira issue closing integration
......
......@@ -2,6 +2,7 @@ class @GroupsSelect
constructor: ->
$('.ajax-groups-select').each (i, select) =>
skip_ldap = $(select).hasClass('skip_ldap')
skip_group = $(select).data("skip-group")
$(select).select2
placeholder: "Search for a group"
......@@ -9,7 +10,13 @@ class @GroupsSelect
minimumInputLength: 0
query: (query) ->
Api.groups query.term, skip_ldap, (groups) ->
data = { results: groups }
data = { results: [] }
for group in groups
continue if skip_group && group.path == skip_group
data.results.push(group)
query.callback(data)
initSelection: (element, callback) ->
......
......@@ -33,7 +33,7 @@ module SelectsHelper
css_class << (opts[:class] || '')
value = opts[:selected] || ''
hidden_field_tag(id, value, class: css_class)
hidden_field_tag(id, value, class: css_class, data: { skip_group: opts[:skip_group] })
end
def admin_email_select_tag(id, opts = {})
......
......@@ -12,6 +12,7 @@ class ProjectGroupLink < ActiveRecord::Base
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
......@@ -24,4 +25,12 @@ class ProjectGroupLink < ActiveRecord::Base
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
......@@ -29,7 +29,7 @@
.form-group
= label_tag :link_group_id, 'Group', class: 'control-label'
.col-sm-10
= groups_select_tag(:link_group_id)
= groups_select_tag(:link_group_id, skip_group: @project.group.try(:path))
.form-group
= label_tag :link_group_access, 'Max access level', class: 'control-label'
.col-sm-10
......
......@@ -394,11 +394,11 @@ ActiveRecord::Schema.define(version: 20150312000132) do
t.string "avatar"
t.string "import_status"
t.float "repository_size", default: 0.0
t.text "merge_requests_template"
t.integer "star_count", default: 0, null: false
t.boolean "merge_requests_rebase_enabled", default: false
t.string "import_type"
t.string "import_source"
t.text "merge_requests_template"
t.boolean "merge_requests_rebase_enabled", default: false
t.boolean "merge_requests_rebase_default", default: true
end
......@@ -514,7 +514,6 @@ ActiveRecord::Schema.define(version: 20150312000132) do
t.string "unconfirmed_email"
t.boolean "hide_no_ssh_key", default: false
t.string "website_url", default: "", null: false
t.datetime "admin_email_unsubscribed_at"
t.string "github_access_token"
t.string "gitlab_access_token"
t.string "notification_email"
......@@ -522,6 +521,7 @@ ActiveRecord::Schema.define(version: 20150312000132) do
t.boolean "password_automatically_set", default: false
t.string "bitbucket_access_token"
t.string "bitbucket_access_token_secret"
t.datetime "admin_email_unsubscribed_at"
end
add_index "users", ["admin"], name: "index_users_on_admin", using: :btree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment