Commit 1cbdc9e6 authored by Sean McGivern's avatar Sean McGivern

Merge branch '288944-move-users-show-json' into 'master'

Move users#show.json to users#activity.json

See merge request gitlab-org/gitlab!48712
parents 248ce183 2f6ba225
......@@ -33,6 +33,8 @@ class UsersController < ApplicationController
end
format.json do
# In 13.8, this endpoint will be removed:
# https://gitlab.com/gitlab-org/gitlab/-/issues/289972
load_events
pager_json("events/_events", @events.count, events: @events)
end
......@@ -42,6 +44,11 @@ class UsersController < ApplicationController
def activity
respond_to do |format|
format.html { render 'show' }
format.json do
load_events
pager_json("events/_events", @events.count, events: @events)
end
end
end
......
......@@ -18,7 +18,7 @@
%h4.gl-flex-grow-1
= Feature.enabled?(:security_auto_fix) && @user.bot? ? s_('UserProfile|Bot activity') : s_('UserProfile|Activity')
= link_to s_('UserProfile|View all'), user_activity_path, class: "hide js-view-all"
.overview-content-list{ data: { href: user_path } }
.overview-content-list{ data: { href: user_activity_path } }
.center.light.loading
.spinner.spinner-md
......
......@@ -139,7 +139,7 @@
- if can?(current_user, :read_cross_project)
%h4.prepend-top-20
= s_('UserProfile|Most Recent Activity')
.content_list{ data: { href: user_path } }
.content_list{ data: { href: user_activity_path } }
.loading
.spinner.spinner-md
- unless @user.bot?
......
---
title: Move users#show.json to users#activity.json
merge_request: 48712
author: Takuya Noguchi
type: other
......@@ -114,6 +114,113 @@ RSpec.describe UsersController do
end
end
describe 'GET #activity' do
context 'with rendered views' do
render_views
describe 'when logged in' do
before do
sign_in(user)
end
it 'renders the show template' do
get :show, params: { username: user.username }
expect(response).to be_successful
expect(response).to render_template('show')
end
end
describe 'when logged out' do
it 'renders the show template' do
get :activity, params: { username: user.username }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('show')
end
end
end
context 'when public visibility level is restricted' do
before do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
end
context 'when logged out' do
it 'redirects to login page' do
get :activity, params: { username: user.username }
expect(response).to redirect_to new_user_session_path
end
end
context 'when logged in' do
before do
sign_in(user)
end
it 'renders show' do
get :activity, params: { username: user.username }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template('show')
end
end
end
context 'when a user by that username does not exist' do
context 'when logged out' do
it 'redirects to login page' do
get :activity, params: { username: 'nonexistent' }
expect(response).to redirect_to new_user_session_path
end
end
context 'when logged in' do
before do
sign_in(user)
end
it 'renders 404' do
get :activity, params: { username: 'nonexistent' }
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'json with events' do
let(:project) { create(:project) }
before do
project.add_developer(user)
Gitlab::DataBuilder::Push.build_sample(project, user)
sign_in(user)
end
it 'loads events' do
get :activity, params: { username: user }, format: :json
expect(assigns(:events)).not_to be_empty
end
it 'hides events if the user cannot read cross project' do
allow(Ability).to receive(:allowed?).and_call_original
expect(Ability).to receive(:allowed?).with(user, :read_cross_project) { false }
get :activity, params: { username: user }, format: :json
expect(assigns(:events)).to be_empty
end
it 'hides events if the user has a private profile' do
Gitlab::DataBuilder::Push.build_sample(project, private_user)
get :activity, params: { username: private_user.username }, format: :json
expect(assigns(:events)).to be_empty
end
end
end
describe 'GET #calendar' do
context 'for user' do
let(:project) { create(:project) }
......
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