Skip to content

Commit 3eb3239

Browse files
zeripathguillep2k
andauthored
Fix repo-list private and total count bugs (#11500)
* Fix repo-list private and total count bugs Signed-off-by: Andrew Thornton <[email protected]> * Ensure limited and private org public repos are displayed on "private" Signed-off-by: Andrew Thornton <[email protected]> * switch from onlyPrivate to is_private Signed-off-by: Andrew Thornton <[email protected]> * Generate swagger Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: guillep2k <[email protected]>
1 parent b797b76 commit 3eb3239

File tree

5 files changed

+23
-62
lines changed

5 files changed

+23
-62
lines changed

models/repo_list.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ type SearchRepoOptions struct {
140140
PriorityOwnerID int64
141141
OrderBy SearchOrderBy
142142
Private bool // Include private repositories in results
143-
OnlyPrivate bool // Include only private repositories in results
144143
StarredByID int64
145144
AllPublic bool // Include also all public repositories of users and public organisations
146145
AllLimited bool // Include also all public repositories of limited organisations
146+
// None -> include public and private
147+
// True -> include just private
148+
// False -> incude just public
149+
IsPrivate util.OptionalBool
147150
// None -> include collaborative AND non-collaborative
148151
// True -> include just collaborative
149152
// False -> incude just non-collaborative
@@ -221,15 +224,8 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
221224
))))
222225
}
223226

224-
if opts.OnlyPrivate {
225-
cond = cond.And(
226-
builder.Or(
227-
builder.Eq{"is_private": true},
228-
builder.In("owner_id", builder.Select("id").From("`user`").Where(
229-
builder.And(
230-
builder.Eq{"type": UserTypeOrganization},
231-
builder.Or(builder.Eq{"visibility": structs.VisibleTypeLimited}, builder.Eq{"visibility": structs.VisibleTypePrivate}),
232-
)))))
227+
if opts.IsPrivate != util.OptionalBoolNone {
228+
cond = cond.And(builder.Eq{"is_private": opts.IsPrivate.IsTrue()})
233229
}
234230

235231
if opts.Template != util.OptionalBoolNone {

routers/api/v1/repo/repo.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func Search(ctx *context.APIContext) {
7878
// in: query
7979
// description: include private repositories this user has access to (defaults to true)
8080
// type: boolean
81-
// - name: onlyPrivate
81+
// - name: is_private
8282
// in: query
83-
// description: only include private repositories this user has access to (defaults to false)
83+
// description: show only pubic, private or all repositories (defaults to all)
8484
// type: boolean
8585
// - name: template
8686
// in: query
@@ -133,7 +133,6 @@ func Search(ctx *context.APIContext) {
133133
TopicOnly: ctx.QueryBool("topic"),
134134
Collaborate: util.OptionalBoolNone,
135135
Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")),
136-
OnlyPrivate: ctx.IsSigned && ctx.QueryBool("onlyPrivate"),
137136
Template: util.OptionalBoolNone,
138137
StarredByID: ctx.QueryInt64("starredBy"),
139138
IncludeDescription: ctx.QueryBool("includeDesc"),
@@ -169,6 +168,10 @@ func Search(ctx *context.APIContext) {
169168
opts.Archived = util.OptionalBoolOf(ctx.QueryBool("archived"))
170169
}
171170

171+
if ctx.Query("is_private") != "" {
172+
opts.IsPrivate = util.OptionalBoolOf(ctx.QueryBool("is_private"))
173+
}
174+
172175
var sortMode = ctx.Query("sort")
173176
if len(sortMode) > 0 {
174177
var sortOrder = ctx.Query("order")

templates/swagger/v1_json.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,8 +1771,8 @@
17711771
},
17721772
{
17731773
"type": "boolean",
1774-
"description": "only include private repositories this user has access to (defaults to false)",
1775-
"name": "onlyPrivate",
1774+
"description": "show only pubic, private or all repositories (defaults to all)",
1775+
"name": "is_private",
17761776
"in": "query"
17771777
},
17781778
{

templates/user/dashboard/repolist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</div>
102102
<div class="ui attached table segment">
103103
<ul class="repo-owner-name-list">
104-
<li v-for="repo in repos" :class="{'private': repo.private}" v-show="showRepo(repo)">
104+
<li v-for="repo in repos" :class="{'private': repo.private}">
105105
<a :href="suburl + '/' + repo.full_name">
106106
<svg :class="'svg ' + repoClass(repo)" width="16" height="16" aria-hidden="true"><use :xlink:href="'#' + repoClass(repo)" /></svg>
107107
<strong class="text truncate item-name">${repo.full_name}</strong>

web_src/js/index.js

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,7 +2744,7 @@ function initVueComponents() {
27442744
}&page=${this.page}&limit=${this.searchLimit}&mode=${this.repoTypes[this.reposFilter].searchMode
27452745
}${this.reposFilter !== 'all' ? '&exclusive=1' : ''
27462746
}${this.archivedFilter === 'archived' ? '&archived=true' : ''}${this.archivedFilter === 'unarchived' ? '&archived=false' : ''
2747-
}${this.privateFilter === 'private' ? '&onlyPrivate=true' : ''}${this.privateFilter === 'public' ? '&private=false' : ''
2747+
}${this.privateFilter === 'private' ? '&is_private=true' : ''}${this.privateFilter === 'public' ? '&is_private=false' : ''
27482748
}`;
27492749
},
27502750
repoTypeCount() {
@@ -2910,56 +2910,18 @@ function initVueComponents() {
29102910
this.searchRepos();
29112911
},
29122912

2913-
showArchivedRepo(repo) {
2914-
switch (this.archivedFilter) {
2915-
case 'both':
2916-
return true;
2917-
case 'unarchived':
2918-
return !repo.archived;
2919-
case 'archived':
2920-
return repo.archived;
2921-
default:
2922-
return !repo.archived;
2923-
}
2924-
},
2925-
2926-
showPrivateRepo(repo) {
2927-
switch (this.privateFilter) {
2928-
case 'both':
2929-
return true;
2930-
case 'public':
2931-
return !repo.private;
2932-
case 'private':
2933-
return repo.private;
2934-
default:
2935-
return true;
2936-
}
2937-
},
2938-
2939-
showFilteredRepo(repo) {
2940-
switch (this.reposFilter) {
2941-
case 'sources':
2942-
return repo.owner.id === this.uid && !repo.mirror && !repo.fork;
2943-
case 'forks':
2944-
return repo.owner.id === this.uid && !repo.mirror && repo.fork;
2945-
case 'mirrors':
2946-
return repo.mirror;
2947-
case 'collaborative':
2948-
return repo.owner.id !== this.uid && !repo.mirror;
2949-
default:
2950-
return true;
2951-
}
2952-
},
2953-
2954-
showRepo(repo) {
2955-
return this.showArchivedRepo(repo) && this.showPrivateRepo(repo) && this.showFilteredRepo(repo);
2956-
},
2957-
29582913
searchRepos() {
29592914
const self = this;
29602915

29612916
this.isLoading = true;
29622917

2918+
if (!this.reposTotalCount) {
2919+
const totalCountSearchURL = `${this.suburl}/api/v1/repos/search?sort=updated&order=desc&uid=${this.uid}&q=&page=1&mode=`;
2920+
$.getJSON(totalCountSearchURL, (_result, _textStatus, request) => {
2921+
self.reposTotalCount = request.getResponseHeader('X-Total-Count');
2922+
});
2923+
}
2924+
29632925
const searchedMode = this.repoTypes[this.reposFilter].searchMode;
29642926
const searchedURL = this.searchURL;
29652927
const searchedQuery = this.searchQuery;

0 commit comments

Comments
 (0)