From 5acba4609a8eb060d91faf42c771da1a62c0170b Mon Sep 17 00:00:00 2001
From: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com>
Date: Fri, 5 Jun 2020 13:41:06 +0200
Subject: [PATCH] Add internal-repo octicon for public repos of private org
 (#11529)

* Show multiple octicons on repo list

* fix mixed spaces/tabs

* Internal repo octicon

* show internal icon in dashboard repolist

* swagger

* fix icon for normal repo on repo page

* don't expose owner visibility directly; provide internal in repo api

* fix icons for forks and mirrors

Co-authored-by: Lauris BH <lauris@nix.lv>
---
 models/repo.go                         | 1 +
 modules/structs/repo.go                | 1 +
 templates/explore/repo_list.tmpl       | 2 ++
 templates/repo/header.tmpl             | 6 ++++++
 templates/swagger/v1_json.tmpl         | 4 ++++
 templates/user/dashboard/repolist.tmpl | 2 +-
 web_src/js/index.js                    | 2 ++
 7 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/models/repo.go b/models/repo.go
index dceeeb89e9..fd2e75a0ea 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -405,6 +405,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
 		AllowRebaseMerge:          allowRebaseMerge,
 		AllowSquash:               allowSquash,
 		AvatarURL:                 repo.avatarLink(e),
+		Internal:                  !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
 	}
 }
 
diff --git a/modules/structs/repo.go b/modules/structs/repo.go
index 832d330e74..2ff1a1ec26 100644
--- a/modules/structs/repo.go
+++ b/modules/structs/repo.go
@@ -88,6 +88,7 @@ type Repository struct {
 	AllowRebaseMerge          bool             `json:"allow_rebase_explicit"`
 	AllowSquash               bool             `json:"allow_squash_merge"`
 	AvatarURL                 string           `json:"avatar_url"`
+	Internal                  bool             `json:"internal"`
 }
 
 // CreateRepoOption options when creating repository
diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl
index 37bd38c5fa..61ef056afc 100644
--- a/templates/explore/repo_list.tmpl
+++ b/templates/explore/repo_list.tmpl
@@ -11,6 +11,8 @@
 				</a>
 				{{if .IsPrivate}}
 					<span class="middle text gold">{{svg "octicon-lock" 16}}</span>
+				{{else if and (not .IsMirror) (not .IsFork) (.Owner.Visibility.IsPrivate) }}
+					<span class="text gold">{{svg "octicon-internal-repo" 16}}</span>
 				{{else if .IsFork}}
 					<span class="middle">{{svg "octicon-repo-forked" 16}}</span>
 				{{else if .IsMirror}}
diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl
index 4daaa201d0..2faaafa442 100644
--- a/templates/repo/header.tmpl
+++ b/templates/repo/header.tmpl
@@ -14,6 +14,12 @@
 				{{else}}
 					{{if .IsPrivate}}
 						{{svg "octicon-lock" 32}}
+					{{else if and (not .IsMirror) (not .IsFork) (.Owner)}}
+						{{if .Owner.Visibility.IsPrivate}}
+							{{svg "octicon-internal-repo" 32}}
+						{{else}}
+							{{svg "octicon-repo" 32}}
+						{{end}}
 					{{else if .IsMirror}}
 						{{svg "octicon-repo-clone" 32}}
 					{{else if .IsFork}}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index d90fafd75f..456d41b9d4 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -14056,6 +14056,10 @@
           "type": "boolean",
           "x-go-name": "IgnoreWhitespaceConflicts"
         },
+        "internal": {
+          "type": "boolean",
+          "x-go-name": "Internal"
+        },
         "internal_tracker": {
           "$ref": "#/definitions/InternalTracker"
         },
diff --git a/templates/user/dashboard/repolist.tmpl b/templates/user/dashboard/repolist.tmpl
index 93dda77d24..4bae23ab1b 100644
--- a/templates/user/dashboard/repolist.tmpl
+++ b/templates/user/dashboard/repolist.tmpl
@@ -101,7 +101,7 @@
 			</div>
 			<div class="ui attached table segment">
 				<ul class="repo-owner-name-list">
-					<li v-for="repo in repos" :class="{'private': repo.private}">
+					<li v-for="repo in repos" :class="{'private': repo.private || repo.internal}">
 						<a :href="suburl + '/' + repo.full_name">
 							<svg :class="'svg ' + repoClass(repo)" width="16" height="16" aria-hidden="true"><use :xlink:href="'#' + repoClass(repo)" /></svg>
 							<strong class="text truncate item-name">${repo.full_name}</strong>
diff --git a/web_src/js/index.js b/web_src/js/index.js
index fa32c64c33..bd3f5da7f4 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -2962,6 +2962,8 @@ function initVueComponents() {
           return `octicon-repo-template${repo.private ? '-private' : ''}`;
         } if (repo.private) {
           return 'octicon-lock';
+        } if (repo.internal) {
+          return 'octicon-internal-repo';
         }
         return 'octicon-repo';
       }