ability to view public repos without authentication
This commit is contained in:
parent
73c03dc2e0
commit
987e53eb39
2 changed files with 23 additions and 7 deletions
|
@ -71,11 +71,6 @@ func (h AdminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
type RepoHandler func(w http.ResponseWriter, r *http.Request, user *User, repo *Repo) error
|
type RepoHandler func(w http.ResponseWriter, r *http.Request, user *User, repo *Repo) error
|
||||||
|
|
||||||
func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
user, err := readUser(r)
|
|
||||||
if err != nil {
|
|
||||||
redirectLogin(w, r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// repository name from the URL parameters
|
// repository name from the URL parameters
|
||||||
hostParam := r.FormValue(":host")
|
hostParam := r.FormValue(":host")
|
||||||
|
@ -84,15 +79,30 @@ func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
repoName := fmt.Sprintf("%s/%s/%s", hostParam, userParam, nameParam)
|
repoName := fmt.Sprintf("%s/%s/%s", hostParam, userParam, nameParam)
|
||||||
|
|
||||||
repo, err := database.GetRepoSlug(repoName)
|
repo, err := database.GetRepoSlug(repoName)
|
||||||
if err != nil {
|
if err != nil || repo == nil {
|
||||||
RenderNotFound(w)
|
RenderNotFound(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retrieve the user from the database
|
||||||
|
user, err := readUser(r)
|
||||||
|
|
||||||
|
// if the user is not found, we can still
|
||||||
|
// serve the page assuming the repository
|
||||||
|
// is public.
|
||||||
|
switch {
|
||||||
|
case err != nil && repo.Private == true:
|
||||||
|
redirectLogin(w, r)
|
||||||
|
return
|
||||||
|
case err != nil && repo.Private == false:
|
||||||
|
h(w, r, nil, repo)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// The User must own the repository OR be a member
|
// The User must own the repository OR be a member
|
||||||
// of the Team that owns the repository OR the repo
|
// of the Team that owns the repository OR the repo
|
||||||
// must not be private.
|
// must not be private.
|
||||||
if user.ID != repo.UserID && repo.Private == false {
|
if repo.Private == false && user.ID != repo.UserID {
|
||||||
if member, _ := database.IsMember(user.ID, repo.TeamID); !member {
|
if member, _ := database.IsMember(user.ID, repo.TeamID); !member {
|
||||||
RenderNotFound(w)
|
RenderNotFound(w)
|
||||||
return
|
return
|
||||||
|
|
|
@ -36,12 +36,18 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
{{ if .User }}
|
||||||
<li><a href="/dashboard">Home</a></li>
|
<li><a href="/dashboard">Home</a></li>
|
||||||
<li><a href="/account/user/profile">Settings</a></li>
|
<li><a href="/account/user/profile">Settings</a></li>
|
||||||
<li><a href="http://drone.readthedocs.org/en/latest/">Help</a></li>
|
<li><a href="http://drone.readthedocs.org/en/latest/">Help</a></li>
|
||||||
<li><a class="btn btn-config" href="/account/admin/settings"><i class="fa fa-cogs"></i></a></li>
|
<li><a class="btn btn-config" href="/account/admin/settings"><i class="fa fa-cogs"></i></a></li>
|
||||||
<li><a href="/new/github.com" class="btn">New Repository</a></li>
|
<li><a href="/new/github.com" class="btn">New Repository</a></li>
|
||||||
<li><a href="/logout" class="btn">Logout</a></li>
|
<li><a href="/logout" class="btn">Logout</a></li>
|
||||||
|
{{ else }}
|
||||||
|
<li><a href="https://github.com/drone/drone">About</a></li>
|
||||||
|
<li><a href="http://drone.readthedocs.org/en/latest/">Help</a></li>
|
||||||
|
<li><a href="/login" class="btn">Login</a></li>
|
||||||
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</div><!-- /.nav-collapse -->
|
</div><!-- /.nav-collapse -->
|
||||||
</div><!-- /.container -->
|
</div><!-- /.container -->
|
||||||
|
|
Loading…
Reference in a new issue