Webhook delivery locking & Hide repo for org members if they don't have access

This commit is contained in:
Unknwon 2014-10-09 19:01:22 -04:00
parent 7b03b1df0e
commit 79262173a6
4 changed files with 31 additions and 4 deletions

View File

@ -1,5 +1,8 @@
[run] [run]
init_cmds = [["./gogs", "web"]] init_cmds = [
["grep", "-rn", "FIXME", "."],
["./gogs", "web"]
]
watch_all = true watch_all = true
watch_dirs = [ watch_dirs = [
"$WORKDIR/conf/locale", "$WORKDIR/conf/locale",

View File

@ -166,7 +166,9 @@ type Repository struct {
} }
func (repo *Repository) GetOwner() (err error) { func (repo *Repository) GetOwner() (err error) {
repo.Owner, err = GetUserById(repo.OwnerId) if repo.Owner == nil {
repo.Owner, err = GetUserById(repo.OwnerId)
}
return err return err
} }
@ -175,6 +177,14 @@ func (repo *Repository) GetMirror() (err error) {
return err return err
} }
func (repo *Repository) HasAccess(uname string) bool {
if err := repo.GetOwner(); err != nil {
return false
}
has, _ := HasAccess(uname, path.Join(repo.Owner.Name, repo.Name), READABLE)
return has
}
// DescriptionHtml does special handles to description and return HTML string. // DescriptionHtml does special handles to description and return HTML string.
func (repo *Repository) DescriptionHtml() template.HTML { func (repo *Repository) DescriptionHtml() template.HTML {
sanitize := func(s string) string { sanitize := func(s string) string {

View File

@ -235,8 +235,22 @@ func UpdateHookTask(t *HookTask) error {
return err return err
} }
var (
// Prevent duplicate deliveries.
// This happens with massive hook tasks cannot finish delivering
// before next shooting starts.
isShooting = false
)
// DeliverHooks checks and delivers undelivered hooks. // DeliverHooks checks and delivers undelivered hooks.
// FIXME: maybe can use goroutine to shoot a number of them at same time?
func DeliverHooks() { func DeliverHooks() {
if isShooting {
return
}
isShooting = true
defer func() { isShooting = false }()
tasks := make([]*HookTask, 0, 10) tasks := make([]*HookTask, 0, 10)
timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second
x.Where("is_delivered=?", false).Iterate(new(HookTask), x.Where("is_delivered=?", false).Iterate(new(HookTask),
@ -255,7 +269,7 @@ func DeliverHooks() {
t.IsDelivered = true t.IsDelivered = true
// TODO: record response. // FIXME: record response.
switch t.Type { switch t.Type {
case GOGS: case GOGS:
{ {

View File

@ -27,7 +27,7 @@
</div> </div>
<div id="org-repo-list"> <div id="org-repo-list">
{{range .Repos}} {{range .Repos}}
{{if or $isMember (not .IsPrivate)}} {{if .HasAccess $.SignedUser.Name}}
<div class="org-repo-item"> <div class="org-repo-item">
<ul class="org-repo-status right"> <ul class="org-repo-status right">
<li><i class="octicon octicon-star"></i> {{.NumStars}}</li> <li><i class="octicon octicon-star"></i> {{.NumStars}}</li>