From 8a6ce2e500d1b842e334bc7016bc4a58a5b49254 Mon Sep 17 00:00:00 2001 From: Baodong Date: Mon, 15 Nov 2021 16:00:04 +0800 Subject: [PATCH 1/9] Add Shimo logo --- app/assets/images/logos/shimo.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 app/assets/images/logos/shimo.svg diff --git a/app/assets/images/logos/shimo.svg b/app/assets/images/logos/shimo.svg new file mode 100644 index 00000000000000..65bd1cc716750c --- /dev/null +++ b/app/assets/images/logos/shimo.svg @@ -0,0 +1 @@ + -- GitLab From 515996b122b275056e0203eae8e8aa41bec45712 Mon Sep 17 00:00:00 2001 From: Baodong Date: Mon, 15 Nov 2021 16:03:35 +0800 Subject: [PATCH 2/9] Add Feature Flag of shimo_integration --- app/models/project.rb | 4 +++- config/feature_flags/development/shimo_integration.yml | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 config/feature_flags/development/shimo_integration.yml diff --git a/app/models/project.rb b/app/models/project.rb index 604158d1a6eb22..0937e83aa0327f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1467,7 +1467,9 @@ def find_or_initialize_integrations end def disabled_integrations - [:shimo] + disabled_integrations = [] + disabled_integrations << 'shimo' unless Feature.enabled?(:shimo_integration, self) + disabled_integrations end def find_or_initialize_integration(name) diff --git a/config/feature_flags/development/shimo_integration.yml b/config/feature_flags/development/shimo_integration.yml new file mode 100644 index 00000000000000..28c0a7859bc936 --- /dev/null +++ b/config/feature_flags/development/shimo_integration.yml @@ -0,0 +1,8 @@ +--- +name: shimo_integration +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73129 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/345356 +milestone: '14.5' +type: development +group: group::integrations +default_enabled: false -- GitLab From 93f6d978c2a60a62cadd2ab6b248a1c22b1b1c42 Mon Sep 17 00:00:00 2001 From: Baodong Date: Mon, 15 Nov 2021 16:05:21 +0800 Subject: [PATCH 3/9] Add has_shimo cache for Shimo model --- app/models/integration.rb | 6 ++++-- app/models/integrations/shimo.rb | 13 +++++++++++++ app/models/project.rb | 2 +- spec/models/integrations/shimo_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/models/integration.rb b/app/models/integration.rb index d3059fa6d4adf7..29d96650a813be 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -14,11 +14,13 @@ class Integration < ApplicationRecord asana assembla bamboo bugzilla buildkite campfire confluence custom_issue_tracker datadog discord drone_ci emails_on_push ewm external_wiki flowdock hangouts_chat irker jira mattermost mattermost_slash_commands microsoft_teams packagist pipelines_email - pivotaltracker prometheus pushover redmine shimo slack slack_slash_commands teamcity unify_circuit webex_teams youtrack zentao + pivotaltracker prometheus pushover redmine slack slack_slash_commands teamcity unify_circuit webex_teams youtrack zentao ].freeze + # TODO Shimo is temporary disabled on group and instance-levels. + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/345677 PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[ - jenkins + jenkins shimo ].freeze # Fake integrations to help with local development. diff --git a/app/models/integrations/shimo.rb b/app/models/integrations/shimo.rb index 4f42fda257758e..0e1023bb7a7b80 100644 --- a/app/models/integrations/shimo.rb +++ b/app/models/integrations/shimo.rb @@ -5,7 +5,11 @@ class Shimo < Integration prop_accessor :external_wiki_url validates :external_wiki_url, presence: true, public_url: true, if: :activated? + after_commit :cache_project_has_shimo + def render? + return false unless Feature.enabled?(:shimo_integration, project) + valid? && activated? end @@ -43,5 +47,14 @@ def fields } ] end + + private + + def cache_project_has_shimo + return unless project && !project.destroyed? + + project.project_setting.save! unless project.project_setting.persisted? + project.project_setting.update_column(:has_shimo, activated?) + end end end diff --git a/app/models/project.rb b/app/models/project.rb index 0937e83aa0327f..01e45737b5fe53 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -448,7 +448,7 @@ def self.integration_association_name(name) delegate :restrict_user_defined_variables, :restrict_user_defined_variables=, to: :ci_cd_settings, allow_nil: true 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?, :has_shimo?, to: :project_setting delegate :active?, to: :prometheus_integration, allow_nil: true, prefix: true delegate :merge_commit_template, :merge_commit_template=, to: :project_setting, allow_nil: true diff --git a/spec/models/integrations/shimo_spec.rb b/spec/models/integrations/shimo_spec.rb index 25df8d2b2498ef..41f3f3c0c16caf 100644 --- a/spec/models/integrations/shimo_spec.rb +++ b/spec/models/integrations/shimo_spec.rb @@ -38,4 +38,26 @@ end end end + + describe 'Caching has_shimo on project_settings' do + let(:project) { create(:project) } + + subject { project.project_setting.has_shimo? } + + it 'sets the property to true when integration is active' do + create(:shimo_integration, project: project, active: true) + + is_expected.to be(true) + end + + it 'sets the property to false when integration is not active' do + create(:shimo_integration, project: project, active: false) + + is_expected.to be(false) + end + + it 'creates a project_setting record if one was not already created' do + expect { create(:shimo_integration) }.to change(ProjectSetting, :count).by(1) + end + end end -- GitLab From 326418656f1a23ef44dad63f049d252c88b97f03 Mon Sep 17 00:00:00 2001 From: Baodong Date: Mon, 15 Nov 2021 16:10:55 +0800 Subject: [PATCH 4/9] Add Shimo menu --- lib/sidebars/projects/menus/shimo_menu.rb | 41 +++++++++++++++++ lib/sidebars/projects/panel.rb | 15 ++++--- .../projects/menus/shimo_menu_spec.rb | 44 +++++++++++++++++++ 3 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 lib/sidebars/projects/menus/shimo_menu.rb create mode 100644 spec/lib/sidebars/projects/menus/shimo_menu_spec.rb diff --git a/lib/sidebars/projects/menus/shimo_menu.rb b/lib/sidebars/projects/menus/shimo_menu.rb new file mode 100644 index 00000000000000..ba022ee3d817cf --- /dev/null +++ b/lib/sidebars/projects/menus/shimo_menu.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Sidebars + module Projects + module Menus + class ShimoMenu < ::Sidebars::Menu + override :link + def link + project_integrations_shimo_index_path(context.project) + end + + override :title + def title + s_('Shimo|Shimo') + end + + override :image_path + def image_path + 'logos/shimo.svg' + end + + override :image_html_options + def image_html_options + { + size: 16 + } + end + + override :render? + def render? + context.project.has_shimo? + end + + override :active_routes + def active_routes + { controller: :shimo } + end + end + end + end +end diff --git a/lib/sidebars/projects/panel.rb b/lib/sidebars/projects/panel.rb index 8fbd71c1543829..6bb4fb52e2ad69 100644 --- a/lib/sidebars/projects/panel.rb +++ b/lib/sidebars/projects/panel.rb @@ -32,8 +32,7 @@ def add_menus add_menu(Sidebars::Projects::Menus::InfrastructureMenu.new(context)) add_menu(Sidebars::Projects::Menus::PackagesRegistriesMenu.new(context)) add_menu(Sidebars::Projects::Menus::AnalyticsMenu.new(context)) - add_menu(confluence_or_wiki_menu) - add_menu(Sidebars::Projects::Menus::ExternalWikiMenu.new(context)) + add_wiki_menus add_menu(Sidebars::Projects::Menus::SnippetsMenu.new(context)) add_menu(Sidebars::Projects::Menus::SettingsMenu.new(context)) add_invite_members_menu @@ -46,10 +45,16 @@ def add_invite_members_menu end end - def confluence_or_wiki_menu - confluence_menu = ::Sidebars::Projects::Menus::ConfluenceMenu.new(context) + def add_wiki_menus + add_menu((third_party_wiki_menu || Sidebars::Projects::Menus::WikiMenu).new(context)) + add_menu(Sidebars::Projects::Menus::ExternalWikiMenu.new(context)) + end + + def third_party_wiki_menu + wiki_menu_list = [::Sidebars::Projects::Menus::ConfluenceMenu] + wiki_menu_list << ::Sidebars::Projects::Menus::ShimoMenu if Feature.enabled?(:shimo_integration, context.project) - confluence_menu.render? ? confluence_menu : Sidebars::Projects::Menus::WikiMenu.new(context) + wiki_menu_list.find { |wiki_menu| wiki_menu.new(context).render? } end end end diff --git a/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb b/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb new file mode 100644 index 00000000000000..8e35284e8882a8 --- /dev/null +++ b/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::Projects::Menus::ShimoMenu do + let_it_be_with_reload(:project) { create(:project) } + + let(:context) { Sidebars::Projects::Context.new(current_user: project.owner, container: project) } + + subject(:shimo_menu) { described_class.new(context) } + + describe '#render?' do + context 'without a valid Shimo integration' do + it "doesn't render the menu" do + expect(shimo_menu.render?).to be_falsey + end + end + + context 'with a valid Shimo integration' do + let_it_be_with_reload(:shimo_integration) { create(:shimo_integration, project: project) } + + context 'when integration is active' do + it 'renders the menu' do + expect(shimo_menu.render?).to eq true + end + + it 'renders menu link' do + expected_url = Rails.application.routes.url_helpers.project_integrations_shimo_index_path(project) + expect(shimo_menu.link).to eq expected_url + end + end + + context 'when integration is inactive' do + before do + shimo_integration.update!(active: false) + end + + it "doesn't render the menu" do + expect(shimo_menu.render?).to eq false + end + end + end + end +end -- GitLab From dcc077a684bfec49f9857207d030615c4d6ca3ee Mon Sep 17 00:00:00 2001 From: Baodong Date: Mon, 15 Nov 2021 16:12:46 +0800 Subject: [PATCH 5/9] Add Shimo index page Add index page view of Shimo integration. Changelog: added --- .../projects/integrations/shimo_controller.rb | 19 ++++++++++ .../integrations/shimo/index.html.haml | 10 +++++ config/routes/project.rb | 4 ++ .../integrations/shimo_controller_spec.rb | 37 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 app/controllers/projects/integrations/shimo_controller.rb create mode 100644 app/views/projects/integrations/shimo/index.html.haml create mode 100644 spec/requests/projects/integrations/shimo_controller_spec.rb diff --git a/app/controllers/projects/integrations/shimo_controller.rb b/app/controllers/projects/integrations/shimo_controller.rb new file mode 100644 index 00000000000000..625c77c543478a --- /dev/null +++ b/app/controllers/projects/integrations/shimo_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Projects + module Integrations + class ShimoController < Projects::ApplicationController + feature_category :integrations + + before_action :ensure_renderable + + def index; end + + private + + def ensure_renderable + render_404 unless Feature.enabled?(:shimo_integration, project) && project.has_shimo? && project.shimo_integration&.render? + end + end + end +end diff --git a/app/views/projects/integrations/shimo/index.html.haml b/app/views/projects/integrations/shimo/index.html.haml new file mode 100644 index 00000000000000..6396f4291424b8 --- /dev/null +++ b/app/views/projects/integrations/shimo/index.html.haml @@ -0,0 +1,10 @@ +- breadcrumb_title s_('Shimo|Shimo Workspace') +- page_title s_('Shimo|Shimo Workspace') +- add_page_specific_style 'page_bundles/wiki' += render layout: 'shared/empty_states/wikis_layout', locals: { image_path: 'illustrations/wiki_login_empty.svg' } do + %h4 + = s_('Shimo|Shimo Workspace integration is enabled') + %p + = format s_("Shimo|You've enabled the Shimo Workspace integration. You can view your wiki directly in Shimo.").html_safe + = link_to @project.shimo_integration.external_wiki_url, target: '_blank', rel: 'noopener noreferrer', class: 'gl-button btn btn-confirm', title: s_('Shimo|Go to Shimo Workspace') do + = s_('Shimo|Go to Shimo Workspace') diff --git a/config/routes/project.rb b/config/routes/project.rb index 7f9b2cc4fbfe32..5be0cc6f704871 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -453,6 +453,10 @@ end end end + + namespace :integrations do + resources :shimo, only: [:index] + end end # End of the /-/ scope. diff --git a/spec/requests/projects/integrations/shimo_controller_spec.rb b/spec/requests/projects/integrations/shimo_controller_spec.rb new file mode 100644 index 00000000000000..29fda7c9bf24f2 --- /dev/null +++ b/spec/requests/projects/integrations/shimo_controller_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Projects::Integrations::ShimoController do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user, developer_projects: [project]) } + let_it_be(:shimo_integration) { create(:shimo_integration, project: project) } + + before do + sign_in(user) + end + + describe 'GET #index' do + context 'when Shimo integration is inactive' do + before do + shimo_integration.update!(active: false) + end + + it 'returns 404 status' do + get project_integrations_shimo_index_url(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when Shimo integration is active' do + it 'renders the "index" template' do + get project_integrations_shimo_index_url(project) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:index) + expect(response.body).to include shimo_integration.external_wiki_url + end + end + end +end -- GitLab From f00190705d0c4944bbd00b3de1d04db30554e18e Mon Sep 17 00:00:00 2001 From: Baodong Date: Mon, 15 Nov 2021 16:18:44 +0800 Subject: [PATCH 6/9] Update gitlab.pot --- locale/gitlab.pot | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 792011abb1ae59..fd5d55d78cb590 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -31871,15 +31871,27 @@ msgstr "" msgid "Sherlock Transactions" msgstr "" +msgid "Shimo|Go to Shimo Workspace" +msgstr "" + msgid "Shimo|Link to a Shimo Workspace from the sidebar." msgstr "" msgid "Shimo|Shimo" msgstr "" +msgid "Shimo|Shimo Workspace" +msgstr "" + msgid "Shimo|Shimo Workspace URL" msgstr "" +msgid "Shimo|Shimo Workspace integration is enabled" +msgstr "" + +msgid "Shimo|You've enabled the Shimo Workspace integration. You can view your wiki directly in Shimo." +msgstr "" + msgid "Should you ever lose your phone or access to your one time password secret, each of these recovery codes can be used one time each to regain access to your account. Please save them in a safe place, or you %{boldStart}will%{boldEnd} lose access to your account." msgstr "" -- GitLab From 317cd2d2dbdd2668e2bc155d11f283d47f1ec108 Mon Sep 17 00:00:00 2001 From: Baodong Date: Wed, 17 Nov 2021 09:41:07 +0800 Subject: [PATCH 7/9] Refactor Shimo routes --- .../{shimo_controller.rb => shimos_controller.rb} | 2 +- .../{shimo/index.html.haml => shimos/show.html.haml} | 0 config/routes/project.rb | 2 +- lib/sidebars/projects/menus/shimo_menu.rb | 2 +- spec/lib/sidebars/projects/menus/shimo_menu_spec.rb | 2 +- .../{shimo_controller_spec.rb => shimos_controller_spec.rb} | 6 +++--- 6 files changed, 7 insertions(+), 7 deletions(-) rename app/controllers/projects/integrations/{shimo_controller.rb => shimos_controller.rb} (85%) rename app/views/projects/integrations/{shimo/index.html.haml => shimos/show.html.haml} (100%) rename spec/requests/projects/integrations/{shimo_controller_spec.rb => shimos_controller_spec.rb} (83%) diff --git a/app/controllers/projects/integrations/shimo_controller.rb b/app/controllers/projects/integrations/shimos_controller.rb similarity index 85% rename from app/controllers/projects/integrations/shimo_controller.rb rename to app/controllers/projects/integrations/shimos_controller.rb index 625c77c543478a..215f6793cf57b2 100644 --- a/app/controllers/projects/integrations/shimo_controller.rb +++ b/app/controllers/projects/integrations/shimos_controller.rb @@ -2,7 +2,7 @@ module Projects module Integrations - class ShimoController < Projects::ApplicationController + class ShimosController < Projects::ApplicationController feature_category :integrations before_action :ensure_renderable diff --git a/app/views/projects/integrations/shimo/index.html.haml b/app/views/projects/integrations/shimos/show.html.haml similarity index 100% rename from app/views/projects/integrations/shimo/index.html.haml rename to app/views/projects/integrations/shimos/show.html.haml diff --git a/config/routes/project.rb b/config/routes/project.rb index 5be0cc6f704871..8a8668a2314913 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -455,7 +455,7 @@ end namespace :integrations do - resources :shimo, only: [:index] + resource :shimo, only: [:show] end end # End of the /-/ scope. diff --git a/lib/sidebars/projects/menus/shimo_menu.rb b/lib/sidebars/projects/menus/shimo_menu.rb index ba022ee3d817cf..c93c4f6a0a469b 100644 --- a/lib/sidebars/projects/menus/shimo_menu.rb +++ b/lib/sidebars/projects/menus/shimo_menu.rb @@ -6,7 +6,7 @@ module Menus class ShimoMenu < ::Sidebars::Menu override :link def link - project_integrations_shimo_index_path(context.project) + project_integrations_shimo_path(context.project) end override :title diff --git a/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb b/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb index 8e35284e8882a8..534267a329e3d5 100644 --- a/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/shimo_menu_spec.rb @@ -25,7 +25,7 @@ end it 'renders menu link' do - expected_url = Rails.application.routes.url_helpers.project_integrations_shimo_index_path(project) + expected_url = Rails.application.routes.url_helpers.project_integrations_shimo_path(project) expect(shimo_menu.link).to eq expected_url end end diff --git a/spec/requests/projects/integrations/shimo_controller_spec.rb b/spec/requests/projects/integrations/shimos_controller_spec.rb similarity index 83% rename from spec/requests/projects/integrations/shimo_controller_spec.rb rename to spec/requests/projects/integrations/shimos_controller_spec.rb index 29fda7c9bf24f2..2b36cb6c1264ad 100644 --- a/spec/requests/projects/integrations/shimo_controller_spec.rb +++ b/spec/requests/projects/integrations/shimos_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Projects::Integrations::ShimoController do +RSpec.describe ::Projects::Integrations::ShimosController do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user, developer_projects: [project]) } let_it_be(:shimo_integration) { create(:shimo_integration, project: project) } @@ -18,7 +18,7 @@ end it 'returns 404 status' do - get project_integrations_shimo_index_url(project) + get project_integrations_shimo_path(project) expect(response).to have_gitlab_http_status(:not_found) end @@ -26,7 +26,7 @@ context 'when Shimo integration is active' do it 'renders the "index" template' do - get project_integrations_shimo_index_url(project) + get project_integrations_shimo_path(project) expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:index) -- GitLab From ca211f83b5d5c65c9e595238d98bcf04061959d1 Mon Sep 17 00:00:00 2001 From: Baodong Date: Wed, 17 Nov 2021 09:46:39 +0800 Subject: [PATCH 8/9] Remove useless format method --- app/views/projects/integrations/shimos/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/integrations/shimos/show.html.haml b/app/views/projects/integrations/shimos/show.html.haml index 6396f4291424b8..92b9e03d5bda21 100644 --- a/app/views/projects/integrations/shimos/show.html.haml +++ b/app/views/projects/integrations/shimos/show.html.haml @@ -5,6 +5,6 @@ %h4 = s_('Shimo|Shimo Workspace integration is enabled') %p - = format s_("Shimo|You've enabled the Shimo Workspace integration. You can view your wiki directly in Shimo.").html_safe + = s_("Shimo|You've enabled the Shimo Workspace integration. You can view your wiki directly in Shimo.") = link_to @project.shimo_integration.external_wiki_url, target: '_blank', rel: 'noopener noreferrer', class: 'gl-button btn btn-confirm', title: s_('Shimo|Go to Shimo Workspace') do = s_('Shimo|Go to Shimo Workspace') -- GitLab From a9f41ed7558f482adffe3ed6730413ea73f1ea6f Mon Sep 17 00:00:00 2001 From: Baodong Date: Wed, 17 Nov 2021 22:24:25 +0800 Subject: [PATCH 9/9] Fix unit tests --- app/controllers/projects/integrations/shimos_controller.rb | 2 +- .../projects/integrations/shimos_controller_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/integrations/shimos_controller.rb b/app/controllers/projects/integrations/shimos_controller.rb index 215f6793cf57b2..827dbb8f3f9ea9 100644 --- a/app/controllers/projects/integrations/shimos_controller.rb +++ b/app/controllers/projects/integrations/shimos_controller.rb @@ -7,7 +7,7 @@ class ShimosController < Projects::ApplicationController before_action :ensure_renderable - def index; end + def show; end private diff --git a/spec/requests/projects/integrations/shimos_controller_spec.rb b/spec/requests/projects/integrations/shimos_controller_spec.rb index 2b36cb6c1264ad..7322143f87e546 100644 --- a/spec/requests/projects/integrations/shimos_controller_spec.rb +++ b/spec/requests/projects/integrations/shimos_controller_spec.rb @@ -11,7 +11,7 @@ sign_in(user) end - describe 'GET #index' do + describe 'GET #show' do context 'when Shimo integration is inactive' do before do shimo_integration.update!(active: false) @@ -25,11 +25,11 @@ end context 'when Shimo integration is active' do - it 'renders the "index" template' do + it 'renders the "show" template' do get project_integrations_shimo_path(project) expect(response).to have_gitlab_http_status(:ok) - expect(response).to render_template(:index) + expect(response).to render_template(:show) expect(response.body).to include shimo_integration.external_wiki_url end end -- GitLab