This instance will be upgraded to Heptapod 0.27.1 on 2021-12-08 at 22:00 UTC+1 (a few minutes of down time)

Commit 95a5cc92 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Restrict the number of permitted boards per project to one

parent c2e9acb8a4d2
......@@ -16,6 +16,7 @@ class Project < ActiveRecord::Base
extend Gitlab::ConfigHelper
NUMBER_OF_PERMITTED_BOARDS = 1
UNKNOWN_IMPORT_URL = 'http://unknown.git'
cache_markdown_field :description, pipeline: :description
......@@ -65,7 +66,7 @@ def update_forks_visibility_level
belongs_to :namespace
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id'
has_many :boards, dependent: :destroy
has_many :boards, before_add: :validate_board_limit, dependent: :destroy
# Project services
has_many :services
......@@ -1338,4 +1339,8 @@ def authorized_for_user_by_shared_projects?(user, min_access_level)
shared_projects.any?
end
def validate_board_limit(board)
raise StandardError, 'Number of permitted boards exceeded' if boards.size >= NUMBER_OF_PERMITTED_BOARDS
end
end
......@@ -94,6 +94,15 @@
end
end
end
describe '#boards' do
it 'raises an error when attempting to add more than one board to the project' do
subject.boards.build
expect { subject.boards.build }.to raise_error(StandardError, 'Number of permitted boards exceeded')
expect(subject.boards.size).to eq 1
end
end
end
describe 'modules' do
......
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