From eaaf0f1247a129d4b9fc5082f768b98cb14fe2b2 Mon Sep 17 00:00:00 2001
From: Coung Ngo <cngo@gitlab.com>
Date: Thu, 15 Feb 2024 09:14:51 +0000
Subject: [PATCH] Hide "email a new issue" on archived issues lists

You cannot create new issues in archived projects so it
does not make sense to show this in the UI

Changelog: fixed
---
 .../list/components/issues_list_app.vue       |  3 ++-
 app/assets/javascripts/issues/list/index.js   |  2 ++
 app/helpers/issues_helper.rb                  |  1 +
 .../projects/merge_requests/index.html.haml   |  2 +-
 .../list/components/issues_list_app_spec.js   |  1 +
 .../list/components/issues_list_app_spec.js   | 19 ++++++++-----------
 spec/helpers/issues_helper_spec.rb            |  1 +
 7 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/app/assets/javascripts/issues/list/components/issues_list_app.vue b/app/assets/javascripts/issues/list/components/issues_list_app.vue
index 8ac7990c28d6a..6add82ebed875 100644
--- a/app/assets/javascripts/issues/list/components/issues_list_app.vue
+++ b/app/assets/javascripts/issues/list/components/issues_list_app.vue
@@ -163,6 +163,7 @@ export default {
     'autocompleteAwardEmojisPath',
     'calendarPath',
     'canBulkUpdate',
+    'canCreateIssue',
     'canReadCrmContact',
     'canReadCrmOrganization',
     'exportCsvPath',
@@ -330,7 +331,7 @@ export default {
       return this.isProject && this.isSignedIn;
     },
     showIssuableByEmail() {
-      return this.initialEmail && this.isSignedIn;
+      return this.initialEmail && this.canCreateIssue;
     },
     showNewIssueDropdown() {
       return !this.isProject && this.hasAnyProjects;
diff --git a/app/assets/javascripts/issues/list/index.js b/app/assets/javascripts/issues/list/index.js
index ab6ff82555498..c2507b4b82cb8 100644
--- a/app/assets/javascripts/issues/list/index.js
+++ b/app/assets/javascripts/issues/list/index.js
@@ -56,6 +56,7 @@ export async function mountIssuesListApp() {
     autocompleteAwardEmojisPath,
     calendarPath,
     canBulkUpdate,
+    canCreateIssue,
     canCreateProjects,
     canEdit,
     canImportIssues,
@@ -116,6 +117,7 @@ export async function mountIssuesListApp() {
       autocompleteAwardEmojisPath,
       calendarPath,
       canBulkUpdate: parseBoolean(canBulkUpdate),
+      canCreateIssue: parseBoolean(canCreateIssue),
       canCreateProjects: parseBoolean(canCreateProjects),
       canReadCrmContact: parseBoolean(canReadCrmContact),
       canReadCrmOrganization: parseBoolean(canReadCrmOrganization),
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index b9499d1307658..f407ac5066ee1 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -183,6 +183,7 @@ def has_issue_date_filter_feature?(namespace, current_user)
   def project_issues_list_data(project, current_user)
     common_issues_list_data(project, current_user).merge(
       can_bulk_update: can?(current_user, :admin_issue, project).to_s,
+      can_create_issue: can?(current_user, :create_issue, project).to_s,
       can_edit: can?(current_user, :admin_project, project).to_s,
       can_import_issues: can?(current_user, :import_issues, @project).to_s,
       can_read_crm_contact: can?(current_user, :read_crm_contact, project.group).to_s,
diff --git a/app/views/projects/merge_requests/index.html.haml b/app/views/projects/merge_requests/index.html.haml
index 86a89f19882a7..e9a9b1fe401e1 100644
--- a/app/views/projects/merge_requests/index.html.haml
+++ b/app/views/projects/merge_requests/index.html.haml
@@ -29,6 +29,6 @@
 - else
   = render 'shared/empty_states/merge_requests', button_path: new_merge_request_path
 
-- if new_merge_request_email
+- if new_merge_request_email && can?(current_user, :create_merge_request_in, @project)
   .gl-text-center.gl-pt-5.gl-pb-7
     .js-issuable-by-email{ data: { initial_email: new_merge_request_email, issuable_type: issuable_type, emails_help_page_path: help_page_path('development/emails', anchor: 'email-namespace'), quick_actions_help_path: help_page_path('user/project/quick_actions'), markdown_help_path: help_page_path('user/markdown'), reset_path: new_issuable_address_project_path(@project, issuable_type: issuable_type) } }
diff --git a/ee/spec/frontend/issues/list/components/issues_list_app_spec.js b/ee/spec/frontend/issues/list/components/issues_list_app_spec.js
index 05a253e035031..ada741b86d9d9 100644
--- a/ee/spec/frontend/issues/list/components/issues_list_app_spec.js
+++ b/ee/spec/frontend/issues/list/components/issues_list_app_spec.js
@@ -55,6 +55,7 @@ describe('EE IssuesListApp component', () => {
     autocompleteAwardEmojisPath: 'autocomplete/award/emojis/path',
     calendarPath: 'calendar/path',
     canBulkUpdate: false,
+    canCreateIssue: false,
     canCreateProjects: false,
     canReadCrmContact: false,
     canReadCrmOrganization: false,
diff --git a/spec/frontend/issues/list/components/issues_list_app_spec.js b/spec/frontend/issues/list/components/issues_list_app_spec.js
index b432a29ee5c76..e0e210ed10f2b 100644
--- a/spec/frontend/issues/list/components/issues_list_app_spec.js
+++ b/spec/frontend/issues/list/components/issues_list_app_spec.js
@@ -103,6 +103,7 @@ describe('CE IssuesListApp component', () => {
     autocompleteAwardEmojisPath: 'autocomplete/award/emojis/path',
     calendarPath: 'calendar/path',
     canBulkUpdate: false,
+    canCreateIssue: false,
     canCreateProjects: false,
     canReadCrmContact: false,
     canReadCrmOrganization: false,
@@ -543,20 +544,16 @@ describe('CE IssuesListApp component', () => {
 
   describe('IssuableByEmail component', () => {
     describe.each`
-      initialEmail | hasAnyIssues | isSignedIn | exists
-      ${false}     | ${false}     | ${false}   | ${false}
-      ${false}     | ${true}      | ${false}   | ${false}
-      ${false}     | ${false}     | ${true}    | ${false}
-      ${false}     | ${true}      | ${true}    | ${false}
-      ${true}      | ${false}     | ${false}   | ${false}
-      ${true}      | ${true}      | ${false}   | ${false}
-      ${true}      | ${false}     | ${true}    | ${true}
-      ${true}      | ${true}      | ${true}    | ${true}
+      initialEmail | canCreateIssue | exists
+      ${false}     | ${false}       | ${false}
+      ${false}     | ${true}        | ${false}
+      ${true}      | ${false}       | ${false}
+      ${true}      | ${true}        | ${true}
     `(
       `when issue creation by email is enabled=$initialEmail`,
-      ({ initialEmail, hasAnyIssues, isSignedIn, exists }) => {
+      ({ initialEmail, canCreateIssue, exists }) => {
         it(`${initialEmail ? 'renders' : 'does not render'}`, () => {
-          wrapper = mountComponent({ provide: { initialEmail, hasAnyIssues, isSignedIn } });
+          wrapper = mountComponent({ provide: { initialEmail, canCreateIssue } });
 
           expect(findIssuableByEmail().exists()).toBe(exists);
         });
diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb
index 6a6808cd8d29b..e9b88a1f5f515 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -208,6 +208,7 @@
         autocomplete_award_emojis_path: autocomplete_award_emojis_path,
         calendar_path: '#',
         can_bulk_update: 'true',
+        can_create_issue: 'true',
         can_edit: 'true',
         can_import_issues: 'true',
         email: current_user&.notification_email_or_default,
-- 
GitLab