Commit f6d180c0 authored by Mayra Cabrera's avatar Mayra Cabrera Committed by Simon Knox

Add project setting to edit commits

A new setting was added under Project > Visibility to allow commit
authors to edit comimt messages on unprotected branches. This setting is
stored in a new column in 'project_settings' table.

Changes are currently under a feature flag.

Related to https://gitlab.com/gitlab-org/gitlab/-/issues/287798
parent 33f49978
......@@ -14,6 +14,7 @@ import {
featureAccessLevel,
} from '../constants';
import { toggleHiddenClassBySelector } from '../external';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
const PAGE_FEATURE_ACCESS_LEVEL = s__('ProjectSettings|Everyone');
......@@ -27,7 +28,7 @@ export default {
GlLink,
GlFormCheckbox,
},
mixins: [settingsMixin],
mixins: [settingsMixin, glFeatureFlagsMixin()],
props: {
currentSettings: {
......@@ -609,5 +610,24 @@ export default {
}}</template>
</gl-form-checkbox>
</project-setting-row>
<project-setting-row
v-if="glFeatures.allowEditingCommitMessages"
ref="allow-editing-commit-messages"
class="gl-mb-4"
>
<input
:value="allowEditingCommitMessages"
type="hidden"
name="project[project_setting_attributes][allow_editing_commit_messages]"
/>
<gl-form-checkbox v-model="allowEditingCommitMessages">
{{ s__('ProjectSettings|Allow editing commit messages') }}
<template #help>{{
s__(
'ProjectSettings|When enabled, commit authors will be able to edit commit messages on unprotected branches.',
)
}}</template>
</gl-form-checkbox>
</project-setting-row>
</div>
</template>
......@@ -34,6 +34,7 @@ class ProjectsController < Projects::ApplicationController
before_action only: [:edit] do
push_frontend_feature_flag(:approval_suggestions, @project, default_enabled: true)
push_frontend_feature_flag(:allow_editing_commit_messages, @project)
end
layout :determine_layout
......@@ -425,6 +426,7 @@ class ProjectsController < Projects::ApplicationController
project_setting_attributes: %i[
show_default_award_emojis
squash_option
allow_editing_commit_messages
]
] + [project_feature_attributes: project_feature_attributes]
end
......
......@@ -612,6 +612,7 @@ module ProjectsHelper
def project_permissions_settings(project)
feature = project.project_feature
{
packagesEnabled: !!project.packages_enabled,
visibilityLevel: project.visibility_level,
......@@ -629,7 +630,8 @@ module ProjectsHelper
emailsDisabled: project.emails_disabled?,
metricsDashboardAccessLevel: feature.metrics_dashboard_access_level,
operationsAccessLevel: feature.operations_access_level,
showDefaultAwardEmojis: project.show_default_award_emojis?
showDefaultAwardEmojis: project.show_default_award_emojis?,
allowEditingCommitMessages: project.allow_editing_commit_messages?
}
end
......
......@@ -409,7 +409,7 @@ class Project < ApplicationRecord
delegate :forward_deployment_enabled, :forward_deployment_enabled=, :forward_deployment_enabled?, to: :ci_cd_settings, prefix: :ci
delegate :actual_limits, :actual_plan_name, to: :namespace, allow_nil: true
delegate :allow_merge_on_skipped_pipeline, :allow_merge_on_skipped_pipeline?,
:allow_merge_on_skipped_pipeline=, :has_confluence?,
:allow_merge_on_skipped_pipeline=, :has_confluence?, :allow_editing_commit_messages?,
to: :project_setting
delegate :active?, to: :prometheus_service, allow_nil: true, prefix: true
......
---
title: Add a project setting to allow editing commit messages
merge_request: 49152
author:
type: other
---
name: allow_editing_commit_messages
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49152/
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/290779
milestone: '13.7'
type: development
group:
default_enabled: false
# frozen_string_literal: true
class AddAllowToEditCommitToProjectSettings < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_column :project_settings, :allow_editing_commit_messages, :boolean, default: false, null: false
end
end
def down
with_lock_retries do
remove_column :project_settings, :allow_editing_commit_messages
end
end
end
700e5d0d5615080f7d747cc71dc437abd24a76b5783f8db7d613036142841e09
\ No newline at end of file
......@@ -15518,6 +15518,7 @@ CREATE TABLE project_settings (
squash_option smallint DEFAULT 3,
has_confluence boolean DEFAULT false NOT NULL,
has_vulnerabilities boolean DEFAULT false NOT NULL,
allow_editing_commit_messages boolean DEFAULT false NOT NULL,
CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL))
);
......
......@@ -21550,6 +21550,9 @@ msgstr ""
msgid "ProjectSettings|Allow"
msgstr ""
msgid "ProjectSettings|Allow editing commit messages"
msgstr ""
msgid "ProjectSettings|Allow users to make copies of your repository to a new project"
msgstr ""
......@@ -21805,6 +21808,9 @@ msgstr ""
msgid "ProjectSettings|When conflicts arise the user is given the option to rebase"
msgstr ""
msgid "ProjectSettings|When enabled, commit authors will be able to edit commit messages on unprotected branches."
msgstr ""
msgid "ProjectSettings|When enabled, issues, merge requests, and snippets will always show thumbs-up and thumbs-down award emoji buttons."
msgstr ""
......
......@@ -692,6 +692,39 @@ RSpec.describe ProjectsController do
end
end
end
context 'when updating boolean values on project_settings' do
using RSpec::Parameterized::TableSyntax
where(:boolean_value, :result) do
'1' | true
'0' | false
1 | true
0 | false
true | true
false | false
end
with_them do
it 'updates project settings attributes accordingly' do
put :update, params: {
namespace_id: project.namespace,
id: project.path,
project: {
project_setting_attributes: {
show_default_award_emojis: boolean_value,
allow_editing_commit_messages: boolean_value
}
}
}
project.reload
expect(project.show_default_award_emojis?).to eq(result)
expect(project.allow_editing_commit_messages?).to eq(result)
end
end
end
end
describe '#transfer', :enable_admin_mode do
......
......@@ -26,6 +26,7 @@ const defaultProps = {
emailsDisabled: false,
packagesEnabled: true,
showDefaultAwardEmojis: true,
allowEditingCommitMessages: false,
},
canDisableEmails: true,
canChangeVisibilityLevel: true,
......@@ -49,7 +50,7 @@ describe('Settings Panel', () => {
let wrapper;
const mountComponent = (
{ currentSettings = {}, ...customProps } = {},
{ currentSettings = {}, glFeatures = {}, ...customProps } = {},
mountFn = shallowMount,
) => {
const propsData = {
......@@ -60,6 +61,9 @@ describe('Settings Panel', () => {
return mountFn(settingsPanel, {
propsData,
provide: {
glFeatures,
},
});
};
......@@ -539,4 +543,18 @@ describe('Settings Panel', () => {
expect(metricsSettingsRow.find('select').attributes('disabled')).toBe('disabled');
});
});
describe('Settings panel with feature flags', () => {
describe('Allow edit of commit message', () => {
it('should show the allow editing of commit messages checkbox', async () => {
wrapper = mountComponent({
glFeatures: { allowEditingCommitMessages: true },
});
await wrapper.vm.$nextTick();
expect(wrapper.find({ ref: 'allow-editing-commit-messages' }).exists()).toBe(true);
});
});
});
});
......@@ -1023,4 +1023,34 @@ RSpec.describe ProjectsHelper do
subject
end
end
describe '#project_permissions_settings' do
context 'with no project_setting associated' do
it 'includes a value for edit commit messages' do
settings = project_permissions_settings(project)
expect(settings[:allowEditingCommitMessages]).to be_falsy
end
end
context 'when commits are allowed to be edited' do
it 'includes the edit commit message value' do
project.create_project_setting(allow_editing_commit_messages: true)
settings = project_permissions_settings(project)
expect(settings[:allowEditingCommitMessages]).to be_truthy
end
end
context 'when commits are not allowed to be edited' do
it 'returns false to the edit commit message value' do
project.create_project_setting(allow_editing_commit_messages: false)
settings = project_permissions_settings(project)
expect(settings[:allowEditingCommitMessages]).to be_falsy
end
end
end
end
......@@ -608,6 +608,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to delegate_method(:name).to(:owner).with_prefix(true).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:root_ancestor).to(:namespace).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:last_pipeline).to(:commit).with_arguments(allow_nil: true) }
it { is_expected.to delegate_method(:allow_editing_commit_messages?).to(:project_setting) }
end
describe 'reference methods' 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