Browse Source

Merge branch 'V20210731.patch' of https://git.openi.org.cn/OpenI/aiforge into contributors

pull/198/head
avadesian 3 years ago
parent
commit
d9bb77aaf0
5 changed files with 57 additions and 13 deletions
  1. +8
    -3
      routers/repo/attachment.go
  2. +20
    -8
      routers/repo/dataset.go
  3. +15
    -0
      routers/secure/user.go
  4. +13
    -1
      routers/user/auth.go
  5. +1
    -1
      web_src/less/_repository.less

+ 8
- 3
routers/repo/attachment.go View File

@@ -141,7 +141,7 @@ func DeleteAttachment(ctx *context.Context) {
}) })
} }


func DownloadUserIsOrg(ctx *context.Context, attach *models.Attachment) bool {
func DownloadUserIsOrgOrCollaboration(ctx *context.Context, attach *models.Attachment) bool {
dataset, err := models.GetDatasetByID(attach.DatasetID) dataset, err := models.GetDatasetByID(attach.DatasetID)
if err != nil { if err != nil {
log.Info("query dataset error") log.Info("query dataset error")
@@ -154,10 +154,15 @@ func DownloadUserIsOrg(ctx *context.Context, attach *models.Attachment) bool {
if repo.Owner.IsOrganization() { if repo.Owner.IsOrganization() {
//log.Info("ower is org.") //log.Info("ower is org.")
if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { if repo.Owner.IsUserPartOfOrg(ctx.User.ID) {
log.Info("user may visit the attach.")
log.Info("org user may visit the attach.")
return true return true
} }
} }
isCollaborator, _ := repo.IsCollaborator(ctx.User.ID)
if isCollaborator {
log.Info("Collaborator user may visit the attach.")
return true
}
} }
} }
return false return false
@@ -190,7 +195,7 @@ func GetAttachment(ctx *context.Context) {


if repository == nil { //If not linked if repository == nil { //If not linked
//if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate { //We block if not the uploader //if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate { //We block if not the uploader
if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && !DownloadUserIsOrg(ctx, attach) { //We block if not the uploader
if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && !DownloadUserIsOrgOrCollaboration(ctx, attach) { //We block if not the uploader
ctx.Error(http.StatusNotFound) ctx.Error(http.StatusNotFound)
return return
} }


+ 20
- 8
routers/repo/dataset.go View File

@@ -28,19 +28,31 @@ func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment
log.Info("can write.") log.Info("can write.")
return list return list
} else { } else {
if repo.Owner == nil {
repo.GetOwner()
}
permission := false
if repo.Owner.IsOrganization() {
if repo.Owner.IsUserPartOfOrg(ctx.User.ID) {
log.Info("user is member of org.")
permission = true
}
}
if !permission {
isCollaborator, _ := repo.IsCollaborator(ctx.User.ID)
if isCollaborator {
log.Info("Collaborator user may visit the attach.")
permission = true
}
}

var publicList []*models.Attachment var publicList []*models.Attachment
for _, attach := range list { for _, attach := range list {
if !attach.IsPrivate { if !attach.IsPrivate {
publicList = append(publicList, attach) publicList = append(publicList, attach)
} else { } else {
if repo.Owner == nil {
repo.GetOwner()
}
if repo.Owner.IsOrganization() {
if repo.Owner.IsUserPartOfOrg(ctx.User.ID) {
log.Info("user is member of org.")
publicList = append(publicList, attach)
}
if permission {
publicList = append(publicList, attach)
} }
} }
} }


+ 15
- 0
routers/secure/user.go View File

@@ -104,6 +104,21 @@ func CreateUser(ctx *context.Context, form api.CreateUserOption) {
} }
return return
} }

err := models.AddEmailAddress(&models.EmailAddress{
UID: u.ID,
Email: form.Email,
IsActivated: !setting.Service.RegisterEmailConfirm,
})

if err != nil {
log.Error("AddEmailAddress failed:%v", err.Error(), ctx.Data["MsgID"])
ctx.JSON(http.StatusInternalServerError, map[string]string{
"error_msg": err.Error(),
})
return
}

log.Trace("Account created (%s): %s", ctx.User.Name, u.Name, ctx.Data["MsgID"]) log.Trace("Account created (%s): %s", ctx.User.Name, u.Name, ctx.Data["MsgID"])


// Send email notification. // Send email notification.


+ 13
- 1
routers/user/auth.go View File

@@ -1165,7 +1165,19 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
} }
return return
} }
log.Trace("Account created: %s", u.Name)
log.Trace("Account created: %s", u.Name, ctx.Data["MsgID"])

err := models.AddEmailAddress(&models.EmailAddress{
UID: u.ID,
Email: form.Email,
IsActivated: !setting.Service.RegisterEmailConfirm,
})

if err != nil {
log.Error("AddEmailAddress failed:%v", err.Error(), ctx.Data["MsgID"])
ctx.ServerError("AddEmailAddress", err)
return
}


// Auto-set admin for the only user. // Auto-set admin for the only user.
if models.CountUsers() == 1 { if models.CountUsers() == 1 {


+ 1
- 1
web_src/less/_repository.less View File

@@ -2685,7 +2685,7 @@ tbody.commit-list {
width: 1127px; width: 1127px;
} }
th .message-wrapper { th .message-wrapper {
max-width: 680px;
max-width: 510px;
} }
} }




Loading…
Cancel
Save