Commit f7f71326 authored by Baodong's avatar Baodong Committed by Markus Koller

Add Shimo integration sidebar menu and landing page

Changelog: changed
parent ac9b0aa0
This diff is collapsed.
# frozen_string_literal: true
module Projects
module Integrations
class ShimosController < Projects::ApplicationController
feature_category :integrations
before_action :ensure_renderable
def show; end
private
def ensure_renderable
render_404 unless Feature.enabled?(:shimo_integration, project) && project.has_shimo? && project.shimo_integration&.render?
end
end
end
end
......@@ -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.
......
......@@ -5,7 +5,11 @@ module Integrations
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 @@ module Integrations
}
]
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
......@@ -448,7 +448,7 @@ class Project < ApplicationRecord
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
......@@ -1467,7 +1467,9 @@ class Project < ApplicationRecord
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)
......
- 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
= 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')
---
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
......@@ -453,6 +453,10 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end
end
end
namespace :integrations do
resource :shimo, only: [:show]
end
end
# End of the /-/ scope.
......
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class ShimoMenu < ::Sidebars::Menu
override :link
def link
project_integrations_shimo_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
......@@ -32,8 +32,7 @@ module Sidebars
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 @@ module Sidebars
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
......
......@@ -31868,15 +31868,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 ""
......
# 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_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
......@@ -38,4 +38,26 @@ RSpec.describe ::Integrations::Shimo do
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
# frozen_string_literal: true
require 'spec_helper'
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) }
before do
sign_in(user)
end
describe 'GET #show' 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_path(project)
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when Shimo integration is active' 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(:show)
expect(response.body).to include shimo_integration.external_wiki_url
end
end
end
end
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