Re-add the AccessRequestable concern
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
178e2758f6
commit
29cb161e92
6 changed files with 55 additions and 15 deletions
13
app/models/concerns/access_requestable.rb
Normal file
13
app/models/concerns/access_requestable.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# == AccessRequestable concern
|
||||||
|
#
|
||||||
|
# Contains functionality related to objects that can receive request for access.
|
||||||
|
#
|
||||||
|
# Used by Project, and Group.
|
||||||
|
#
|
||||||
|
module AccessRequestable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
def request_access(user)
|
||||||
|
Members::RequestAccessService.new(self, user).execute
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,6 +3,7 @@ require 'carrierwave/orm/activerecord'
|
||||||
class Group < Namespace
|
class Group < Namespace
|
||||||
include Gitlab::ConfigHelper
|
include Gitlab::ConfigHelper
|
||||||
include Gitlab::VisibilityLevel
|
include Gitlab::VisibilityLevel
|
||||||
|
include AccessRequestable
|
||||||
include Referable
|
include Referable
|
||||||
|
|
||||||
has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source, class_name: 'GroupMember'
|
has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source, class_name: 'GroupMember'
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Project < ActiveRecord::Base
|
||||||
include Gitlab::ShellAdapter
|
include Gitlab::ShellAdapter
|
||||||
include Gitlab::VisibilityLevel
|
include Gitlab::VisibilityLevel
|
||||||
include Gitlab::CurrentSettings
|
include Gitlab::CurrentSettings
|
||||||
|
include AccessRequestable
|
||||||
include Referable
|
include Referable
|
||||||
include Sortable
|
include Sortable
|
||||||
include AfterCommitQueue
|
include AfterCommitQueue
|
||||||
|
|
40
spec/models/concerns/access_requestable_spec.rb
Normal file
40
spec/models/concerns/access_requestable_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe AccessRequestable do
|
||||||
|
describe 'Group' do
|
||||||
|
describe '#request_access' do
|
||||||
|
let(:group) { create(:group, :public) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
it { expect(group.request_access(user)).to be_a(GroupMember) }
|
||||||
|
it { expect(group.request_access(user).user).to eq(user) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#access_requested?' do
|
||||||
|
let(:group) { create(:group, :public) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
before { group.request_access(user) }
|
||||||
|
|
||||||
|
it { expect(group.requesters.exists?(user_id: user)).to be_truthy }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Project' do
|
||||||
|
describe '#request_access' do
|
||||||
|
let(:project) { create(:empty_project, :public) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
it { expect(project.request_access(user)).to be_a(ProjectMember) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#access_requested?' do
|
||||||
|
let(:project) { create(:empty_project, :public) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
before { project.request_access(user) }
|
||||||
|
|
||||||
|
it { expect(project.requesters.exists?(user_id: user)).to be_truthy }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -105,13 +105,6 @@ describe Group, models: true do
|
||||||
it { expect(group.human_name).to eq(group.name) }
|
it { expect(group.human_name).to eq(group.name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#request_access' do
|
|
||||||
let(:user) { create(:user) }
|
|
||||||
|
|
||||||
it { expect(group.request_access(user)).to be_a(GroupMember) }
|
|
||||||
it { expect(group.request_access(user).user).to eq(user) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#add_user' do
|
describe '#add_user' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
before { group.add_user(user, GroupMember::MASTER) }
|
before { group.add_user(user, GroupMember::MASTER) }
|
||||||
|
|
|
@ -942,14 +942,6 @@ describe Project, models: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#request_access' do
|
|
||||||
let(:project) { create(:empty_project, :public) }
|
|
||||||
let(:user) { create(:user) }
|
|
||||||
|
|
||||||
it { expect(project.request_access(user)).to be_a(ProjectMember) }
|
|
||||||
it { expect(project.request_access(user).user).to eq(user) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '.search' do
|
describe '.search' do
|
||||||
let(:project) { create(:project, description: 'kitten mittens') }
|
let(:project) { create(:project, description: 'kitten mittens') }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue