Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
62a9b70c
Commit
62a9b70c
authored
Jun 24, 2020
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
parent
43130a83
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
79 additions
and
11 deletions
+79
-11
app/controllers/projects/wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+1
-1
app/models/project_wiki.rb
app/models/project_wiki.rb
+8
-0
app/views/projects/wikis/_sidebar.html.haml
app/views/projects/wikis/_sidebar.html.haml
+1
-1
changelogs/unreleased/correctly-count-wiki-pages-in-sidebar.yml
...logs/unreleased/correctly-count-wiki-pages-in-sidebar.yml
+5
-0
lib/gitlab/wiki_pages.rb
lib/gitlab/wiki_pages.rb
+3
-0
spec/controllers/projects/wikis_controller_spec.rb
spec/controllers/projects/wikis_controller_spec.rb
+2
-3
spec/features/projects/wiki/user_creates_wiki_page_spec.rb
spec/features/projects/wiki/user_creates_wiki_page_spec.rb
+21
-6
spec/models/project_wiki_spec.rb
spec/models/project_wiki_spec.rb
+38
-0
No files found.
app/controllers/projects/wikis_controller.rb
View file @
62a9b70c
...
...
@@ -144,7 +144,7 @@ class Projects::WikisController < Projects::ApplicationController
@sidebar_page
=
@project_wiki
.
find_sidebar
(
params
[
:version_id
])
unless
@sidebar_page
# Fallback to default sidebar
@sidebar_wiki_entries
=
WikiPage
.
group_by_directory
(
@project_wiki
.
list_pages
(
limit:
15
))
@sidebar_wiki_entries
,
@sidebar_limited
=
@project_wiki
.
sidebar_entries
end
rescue
ProjectWiki
::
CouldNotCreateWikiError
flash
[
:notice
]
=
_
(
"Could not create Wiki Repository at this time. Please try again later."
)
...
...
app/models/project_wiki.rb
View file @
62a9b70c
...
...
@@ -114,6 +114,14 @@ class ProjectWiki
end
end
def
sidebar_entries
(
limit:
Gitlab
::
WikiPages
::
MAX_SIDEBAR_PAGES
,
**
options
)
pages
=
list_pages
(
**
options
.
merge
(
limit:
limit
+
1
))
limited
=
pages
.
size
>
limit
pages
=
pages
.
first
(
limit
)
if
limited
[
WikiPage
.
group_by_directory
(
pages
),
limited
]
end
# Finds a page within the repository based on a tile
# or slug.
#
...
...
app/views/projects/wikis/_sidebar.html.haml
View file @
62a9b70c
...
...
@@ -17,6 +17,6 @@
%ul
.wiki-pages
=
render
@sidebar_wiki_entries
,
context:
'sidebar'
.block.w-100
-
if
@sidebar_
wiki_entries
&
.
length
.
to_i
>=
15
-
if
@sidebar_
limited
=
link_to
project_wikis_pages_path
(
@project
),
class:
'btn btn-block'
do
=
s_
(
"Wiki|View All Pages"
)
changelogs/unreleased/correctly-count-wiki-pages-in-sidebar.yml
0 → 100644
View file @
62a9b70c
---
title
:
Correctly count wiki pages in sidebar
merge_request
:
30508
author
:
type
:
fixed
lib/gitlab/wiki_pages.rb
View file @
62a9b70c
...
...
@@ -11,5 +11,8 @@ module Gitlab
# through the GitLab web interface and API:
MAX_TITLE_BYTES
=
245
# reserving 10 bytes for the file extension
MAX_DIRECTORY_BYTES
=
255
# Limit the number of pages displayed in the wiki sidebar.
MAX_SIDEBAR_PAGES
=
15
end
end
spec/controllers/projects/wikis_controller_spec.rb
View file @
62a9b70c
...
...
@@ -98,13 +98,12 @@ describe Projects::WikisController do
let
(
:id
)
{
wiki_title
}
it
'limits the retrieved pages for the sidebar'
do
expect
(
controller
).
to
receive
(
:load_wiki
).
and_return
(
project_wiki
)
expect
(
project_wiki
).
to
receive
(
:list_pages
).
with
(
limit:
15
).
and_call_original
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
assigns
(
:page
).
title
).
to
eq
(
wiki_title
)
expect
(
assigns
(
:sidebar_wiki_entries
)).
to
contain_exactly
(
an_instance_of
(
WikiPage
))
expect
(
assigns
(
:sidebar_limited
)).
to
be
(
false
)
end
context
'when page content encoding is invalid'
do
...
...
spec/features/projects/wiki/user_creates_wiki_page_spec.rb
View file @
62a9b70c
...
...
@@ -312,6 +312,7 @@ describe "User creates wiki page" do
visit
(
project_wikis_path
(
project
))
expect
(
page
).
to
have_content
(
'another'
)
expect
(
page
).
not_to
have_link
(
'View All Pages'
)
end
context
'when there is a customized sidebar'
do
...
...
@@ -328,17 +329,31 @@ describe "User creates wiki page" do
end
end
context
'when there are 15 existing pages'
do
before
do
(
1
..
5
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
wiki
,
title:
"my page
#{
i
}
"
)
}
(
6
..
10
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
wiki
,
title:
"parent/my page
#{
i
}
"
)
}
(
11
..
15
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
wiki
,
title:
"grandparent/parent/my page
#{
i
}
"
)
}
end
it
'shows all pages in the sidebar'
do
visit
(
project_wikis_path
(
project
))
(
1
..
15
).
each
{
|
i
|
expect
(
page
).
to
have_content
(
"my page
#{
i
}
"
)
}
expect
(
page
).
not_to
have_link
(
'View All Pages'
)
end
context
'when there are more than 15 existing pages'
do
before
do
create
(
:wiki_page
,
wiki:
wiki
,
attrs:
{
title:
'home'
,
content:
'home'
})
(
1
..
14
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
wiki
,
attrs:
{
title:
"page-
#{
i
}
"
,
content:
"page
#{
i
}
"
})
}
create
(
:wiki_page
,
wiki:
wiki
,
title:
'my page 16'
)
end
it
'renders a default sidebar when there is no customized
sidebar'
do
it
'shows the first 15 pages in the
sidebar'
do
visit
(
project_wikis_path
(
project
))
expect
(
page
).
to
have_content
(
'View All Pages'
)
expect
(
page
).
to
have_content
(
'page 1'
)
expect
(
page
).
to
have_text
(
'my page'
,
count:
15
)
expect
(
page
).
to
have_link
(
'View All Pages'
)
end
end
end
end
...
...
spec/models/project_wiki_spec.rb
View file @
62a9b70c
...
...
@@ -175,6 +175,44 @@ describe ProjectWiki do
end
end
describe
'#sidebar_entries'
do
before
do
(
1
..
5
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
project_wiki
,
title:
"my page
#{
i
}
"
)
}
(
6
..
10
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
project_wiki
,
title:
"parent/my page
#{
i
}
"
)
}
(
11
..
15
).
each
{
|
i
|
create
(
:wiki_page
,
wiki:
project_wiki
,
title:
"grandparent/parent/my page
#{
i
}
"
)
}
end
def
total_pages
(
entries
)
entries
.
sum
do
|
entry
|
entry
.
is_a?
(
WikiDirectory
)
?
entry
.
pages
.
size
:
1
end
end
context
'when the number of pages does not exceed the limit'
do
it
'returns all pages grouped by directory and limited is false'
do
entries
,
limited
=
subject
.
sidebar_entries
expect
(
entries
.
size
).
to
be
(
7
)
expect
(
total_pages
(
entries
)).
to
be
(
15
)
expect
(
limited
).
to
be
(
false
)
end
end
context
'when the number of pages exceeds the limit'
do
before
do
create
(
:wiki_page
,
wiki:
project_wiki
,
title:
'my page 16'
)
end
it
'returns 15 pages grouped by directory and limited is true'
do
entries
,
limited
=
subject
.
sidebar_entries
expect
(
entries
.
size
).
to
be
(
8
)
expect
(
total_pages
(
entries
)).
to
be
(
15
)
expect
(
limited
).
to
be
(
true
)
end
end
end
describe
"#find_page"
do
before
do
create_page
(
"index page"
,
"This is an awesome Gollum Wiki"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment