Commit 61462b0b authored by Martin Wortschack's avatar Martin Wortschack Committed by Mayra Cabrera

Add skeleton for onboarding helper

- Add controller
- Add specs
- Mount app
- Add  specs
parent 43f3274e
......@@ -6,18 +6,14 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
before_action :set_non_archived_param
before_action :projects, only: [:index]
before_action :default_sorting
skip_cross_project_access_check :index, :starred
def index
@projects = load_projects(params.merge(non_public: true))
respond_to do |format|
format.html do
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/40260
Gitlab::GitalyClient.allow_n_plus_1_calls do
render
end
render_projects
end
format.atom do
load_events
......@@ -51,6 +47,17 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
private
def projects
@projects ||= load_projects(params.merge(non_public: true))
end
def render_projects
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/40260
Gitlab::GitalyClient.allow_n_plus_1_calls do
render
end
end
def default_sorting
params[:sort] ||= 'latest_activity_desc'
@sort = params[:sort]
......@@ -81,3 +88,5 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
Events::RenderService.new(current_user).execute(@events, atom_request: request.format.atom?)
end
end
Dashboard::ProjectsController.prepend(EE::Dashboard::ProjectsController)
......@@ -243,6 +243,7 @@ module ProjectsHelper
# TODO: Remove this method when removing the feature flag
# https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/11209#note_162234863
# make sure to remove from the EE specific controller as well: ee/app/controllers/ee/dashboard/projects_controller.rb
def show_projects?(projects, params)
Feature.enabled?(:project_list_filter_bar) || !!(params[:personal] || params[:name] || any_projects?(projects))
end
......
......@@ -10,4 +10,6 @@
= render 'layouts/page', sidebar: sidebar, nav: nav
= footer_message
= render_if_exists "shared/onboarding_guide"
= yield :scripts_body
import $ from 'jquery';
import initEETrialBanner from 'ee/ee_trial_banner';
import trackNavbarEvents from 'ee/event_tracking/navbar';
import initOnboarding from 'ee/onboarding/onboarding_helper';
$(() => {
/**
......@@ -12,4 +13,6 @@ $(() => {
initEETrialBanner();
trackNavbarEvents();
initOnboarding();
});
<script>
export default {};
</script>
<template>
<div></div>
</template>
import Vue from 'vue';
import OnboardingApp from './components/app.vue';
export default function() {
const el = document.getElementById('js-onboarding-helper');
if (!el) {
return false;
}
return new Vue({
el,
components: {
OnboardingApp,
},
render(h) {
return h(OnboardingApp, {
props: {},
});
},
});
}
# frozen_string_literal: true
module EE
module Dashboard
module ProjectsController
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
private
override :render_projects
def render_projects
if show_onboarding_welcome_page?
redirect_to explore_onboarding_index_path
else
super
end
end
def show_onboarding_welcome_page?
return false unless ::Gitlab.com?
return false if cookies['onboarding_dismissed'] == 'true'
::Feature.enabled?(:user_onboarding) && !show_projects?(projects, params)
end
end
end
end
......@@ -11,7 +11,9 @@ class Explore::OnboardingController < Explore::ApplicationController
def set_project!
@project = get_onboarding_demo_project
render_404 unless @project && can?(current_user, :read_project, @project)
return render_404 unless @project && can?(current_user, :read_project, @project)
session[:onboarding_project] = { project_full_path: @project.web_url, project_name: @project.name }
end
def get_onboarding_demo_project
......
- onboarding_project = session[:onboarding_project]
- return unless onboarding_project
#js-onboarding-helper{ data: { project_full_path: onboarding_project[:project_full_path], project_name: onboarding_project[:project_name] } }
#js-onboarding-action-popover
# frozen_string_literal: true
require 'spec_helper'
describe Dashboard::ProjectsController do
include ExternalAuthorizationServiceHelpers
let(:user) { create(:user) }
describe 'GET #index' do
before do
sign_in(user)
end
context 'onboarding welcome page' do
before do
allow(Gitlab).to receive(:com?) { true }
end
shared_examples '200 status' do
it 'renders the index template' do
get :index
expect(response).to have_gitlab_http_status(200)
expect(response).to render_template(:index)
end
end
context 'when the feature is enabled' do
before do
stub_feature_flags(user_onboarding: true)
end
context 'and the user does not have projects' do
before do
stub_feature_flags(project_list_filter_bar: false)
end
it 'renders the welcome page if it has not dismissed onboarding' do
allow(controller).to receive(:cookies).and_return({ 'onboarding_dismissed' => 'false' })
get :index
expect(response).to redirect_to(explore_onboarding_index_path)
end
it 'renders the index template if it has dismissed the onboarding' do
allow(controller).to receive(:cookies).and_return({ 'onboarding_dismissed' => 'true' })
get :index
expect(response).to have_gitlab_http_status(200)
expect(response).to render_template(:index)
end
end
context 'and the user has projects' do
let(:project) { create(:project) }
before do
project.add_developer(user)
end
it_behaves_like '200 status'
end
end
context 'when the feature is disabled' do
before do
stub_feature_flags(user_onboarding: false)
end
it_behaves_like '200 status'
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Explore::OnboardingController do
let(:user) { create(:user, username: 'gitlab-org') }
let(:project) { create(:project, path: 'gitlab-ce', namespace: user.namespace) }
before do
allow(Gitlab).to receive(:com?) { true }
sign_in(user)
project.add_guest(user)
end
describe 'GET #index' do
context 'when the feature is enabled' do
before do
stub_feature_flags(user_onboarding: true)
end
it 'renders index with 200 status code and sets the session variable if the user is authenticated' do
get :index
expect(response).to have_gitlab_http_status(200)
expect(response).to render_template(:index)
expect(session[:onboarding_project]).to eq({ project_full_path: project.web_url, project_name: project.name })
end
end
context 'when the feature is disabled' do
before do
stub_feature_flags(user_onboarding: false)
end
it 'returns 404' do
get :index
expect(response).to have_gitlab_http_status(404)
expect(session[:onboarding_project]).to be_nil
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