From 8738c29008421eb638343893857449af0f4613e3 Mon Sep 17 00:00:00 2001 From: avadesian Date: Tue, 3 Aug 2021 16:29:30 +0800 Subject: [PATCH 01/17] merge contributors having different names or different emails --- routers/repo/view.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 76593ecc7..5c116285f 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -569,10 +569,19 @@ func safeURL(address string) string { } type ContributorInfo struct { - UserInfo *models.User - Email string // for contributor who is not a registered user + UserInfo *models.User // nil for contributor who is not a registered user + Email string + CommitCnt int } +func getContributorInfo(contributorInfos []*ContributorInfo, email string) *ContributorInfo{ + for _, c := range contributorInfos { + if strings.Compare(c.Email,email) == 0 { + return c + } + } + return nil +} // Home render repository home page func Home(ctx *context.Context) { if len(ctx.Repo.Units) > 0 { @@ -583,12 +592,17 @@ func Home(ctx *context.Context) { for _, c := range contributors { user, err := models.GetUserByEmail(c.Email) if err == nil { - contributorInfos = append(contributorInfos, &ContributorInfo{ - user, c.Email, - }) + existedContributorInfo := getContributorInfo(contributorInfos,user.Email) + if existedContributorInfo != nil { + existedContributorInfo.CommitCnt += c.CommitCnt + }else{ + contributorInfos = append(contributorInfos, &ContributorInfo{ + user, user.Email,c.CommitCnt, + }) + } } else { contributorInfos = append(contributorInfos, &ContributorInfo{ - nil, c.Email, + nil, c.Email,c.CommitCnt, }) } } From d0e86b957eed0ec2e39987dae69b1c19ff1d2304 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 3 Aug 2021 16:31:03 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=9B=A2=E9=98=9F=E6=98=BE=E7=A4=BA=E5=8F=8A=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=8E=A7=E5=88=B6=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8F=A6?= =?UTF-8?q?=E5=A4=96=E5=B0=9D=E8=AF=95=E4=B8=8A=E4=BC=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E6=97=B6=E5=8F=8A=E6=97=B6=E5=88=A0=E9=99=A4js?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 29 +++++++++++++++++++++++++++-- routers/repo/dataset.go | 33 ++++++++++++++++++++++++++++----- web_src/js/components/MinioUploader.vue | 1 + 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index b59f4ffc7..a79955e8c 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -141,6 +141,28 @@ func DeleteAttachment(ctx *context.Context) { }) } +func DownloadUserIsOrg(ctx *context.Context, attach *models.Attachment) bool { + dataset, err := models.GetDatasetByID(attach.DatasetID) + if err != nil { + log.Info("query dataset error") + } else { + repo, err := models.GetRepositoryByID(dataset.RepoID) + if err != nil { + log.Info("query repo error.") + } else { + repo.GetOwner() + if repo.Owner.IsOrganization() { + log.Info("ower is org.") + if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { + log.Info("user may be visit the attach.") + return false + } + } + } + } + return true +} + // GetAttachment serve attachements func GetAttachment(ctx *context.Context) { typeCloudBrain := ctx.QueryInt("type") @@ -167,11 +189,14 @@ func GetAttachment(ctx *context.Context) { } 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 ctx.Error(http.StatusNotFound) return } + } else { //If we have the repository we check access + perm, err := models.GetUserRepoPermission(repository, ctx.User) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error()) @@ -205,7 +230,7 @@ func GetAttachment(ctx *context.Context) { if setting.Attachment.StoreType == storage.MinioStorageType { url := "" if typeCloudBrain == models.TypeCloudBrainOne { - url, err = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath + attach.RelativePath(), attach.Name) + url, err = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath+attach.RelativePath(), attach.Name) if err != nil { ctx.ServerError("PresignedGetURL", err) return diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 3be36fbe4..e5bc54b7d 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -1,15 +1,13 @@ package repo import ( - "sort" - - "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" + "sort" ) const ( @@ -36,7 +34,32 @@ func filterPrivateAttachments(ctx *context.Context, list []*models.Attachment) [ } return publicList } +} + +func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment, repo *models.Repository) []*models.Attachment { + if ctx.Repo.CanWrite(models.UnitTypeDatasets) { + log.Info("can write.") + return list + } else { + var publicList []*models.Attachment + for _, attach := range list { + if !attach.IsPrivate { + publicList = append(publicList, attach) + } 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) + } + } + } + } + return publicList + } } func DatasetIndex(ctx *context.Context) { @@ -60,7 +83,7 @@ func DatasetIndex(ctx *context.Context) { ctx.ServerError("GetDatasetAttachments", err) return } - attachments := filterPrivateAttachments(ctx, dataset.Attachments) + attachments := newFilterPrivateAttachments(ctx, dataset.Attachments, repo) ctx.Data["SortType"] = ctx.Query("sort") switch ctx.Query("sort") { diff --git a/web_src/js/components/MinioUploader.vue b/web_src/js/components/MinioUploader.vue index 9d845650a..1dc92e4b3 100755 --- a/web_src/js/components/MinioUploader.vue +++ b/web_src/js/components/MinioUploader.vue @@ -335,6 +335,7 @@ export default { async function uploadMinio(url, e) { const res = await axios.put(url, e.target.result); + delete e.target.result etags[currentChunk] = res.headers.etag; } From 89d699987664cc6e5334886517fe4fc10c5a56a9 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 3 Aug 2021 16:51:44 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3=E6=96=B9=E6=B3=95=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E5=B8=A6=E4=BA=86=E8=BF=94=E5=9B=9E=E5=80=BC=E6=B7=B7=E6=B7=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index a79955e8c..3e92471bb 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -152,15 +152,15 @@ func DownloadUserIsOrg(ctx *context.Context, attach *models.Attachment) bool { } else { repo.GetOwner() if repo.Owner.IsOrganization() { - log.Info("ower is org.") + //log.Info("ower is org.") if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { - log.Info("user may be visit the attach.") - return false + log.Info("user may visit the attach.") + return true } } } } - return true + return false } // GetAttachment serve attachements @@ -190,7 +190,7 @@ func GetAttachment(ctx *context.Context) { 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) && DownloadUserIsOrg(ctx, attach) { //We block if not the uploader + if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && !DownloadUserIsOrg(ctx, attach) { //We block if not the uploader ctx.Error(http.StatusNotFound) return } From a36d39ce4dfe7aaf0ce52b8cb8a9fe4de7c193e8 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 3 Aug 2021 16:56:33 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/dataset.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index e5bc54b7d..53a2969fb 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -22,20 +22,6 @@ func MustEnableDataset(ctx *context.Context) { } } -func filterPrivateAttachments(ctx *context.Context, list []*models.Attachment) []*models.Attachment { - if ctx.Repo.CanWrite(models.UnitTypeDatasets) { - return list - } else { - var publicList []*models.Attachment - for _, attach := range list { - if !attach.IsPrivate { - publicList = append(publicList, attach) - } - } - return publicList - } -} - func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment, repo *models.Repository) []*models.Attachment { if ctx.Repo.CanWrite(models.UnitTypeDatasets) { From 69992b0198340572ba207a37c5920bb531ffc730 Mon Sep 17 00:00:00 2001 From: hit172587zpz Date: Tue, 3 Aug 2021 17:35:01 +0800 Subject: [PATCH 05/17] fix issue 185 --- web_src/less/_repository.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 0382595b3..9103d7e24 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -2685,7 +2685,7 @@ tbody.commit-list { width: 1127px; } th .message-wrapper { - max-width: 680px; + max-width: 510px; } } From 43e65fce265c7d6d50f82276f27f421f39937e47 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 3 Aug 2021 19:48:05 +0800 Subject: [PATCH 06/17] fix-186 --- routers/secure/user.go | 15 +++++++++++++++ routers/user/auth.go | 14 +++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/routers/secure/user.go b/routers/secure/user.go index 8c06b0dab..1e88a7381 100755 --- a/routers/secure/user.go +++ b/routers/secure/user.go @@ -104,6 +104,21 @@ func CreateUser(ctx *context.Context, form api.CreateUserOption) { } 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"]) // Send email notification. diff --git a/routers/user/auth.go b/routers/user/auth.go index dc5c5536b..dd66fcb8b 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -1165,7 +1165,19 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo } 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. if models.CountUsers() == 1 { From fe0e093a1d6189e1ea9259921a4fd9e1c7e8dfde Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 4 Aug 2021 10:21:40 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=A2=9E=E5=8A=A0=E5=8D=8F=E4=BD=9C=E8=80=85=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=9F=A5=E7=9C=8B=E5=8F=8A=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 11 ++++++++--- routers/repo/dataset.go | 25 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 3e92471bb..830f193ee 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -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) if err != nil { log.Info("query dataset error") @@ -154,10 +154,15 @@ func DownloadUserIsOrg(ctx *context.Context, attach *models.Attachment) bool { if repo.Owner.IsOrganization() { //log.Info("ower is org.") if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { - log.Info("user may visit the attach.") + log.Info("org user may visit the attach.") return true } } + isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) + if isCollaborator { + log.Info("Collaborator user may visit the attach.") + return true + } } } return false @@ -190,7 +195,7 @@ func GetAttachment(ctx *context.Context) { 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) && !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) return } diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 53a2969fb..8b2f2abd3 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -28,19 +28,28 @@ func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment log.Info("can write.") return list } 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 + } + } + isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) + if isCollaborator { + log.Info("Collaborator user may visit the attach.") + permission = true + } var publicList []*models.Attachment for _, attach := range list { if !attach.IsPrivate { publicList = append(publicList, attach) } 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) } } } From 555330464c6b9d8d68577bc8be6efc4c376d4b16 Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 4 Aug 2021 10:34:30 +0800 Subject: [PATCH 08/17] =?UTF-8?q?-m=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=8D=8F=E4=BD=9C=E8=80=85=E6=98=BE=E7=A4=BA=E5=8F=8A?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=9D=83=E9=99=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/dataset.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 8b2f2abd3..bdadd2066 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -38,11 +38,14 @@ func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment permission = true } } - isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) - if isCollaborator { - log.Info("Collaborator user may visit the attach.") - 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 for _, attach := range list { if !attach.IsPrivate { From 77c40c7889046e80959449bff1d1ad610520d2dd Mon Sep 17 00:00:00 2001 From: avadesian Date: Wed, 4 Aug 2021 11:26:42 +0800 Subject: [PATCH 09/17] merge duplicate committers who are not system users --- routers/repo/view.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 5c116285f..945f6b0e0 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -590,20 +590,31 @@ func Home(ctx *context.Context) { if err == nil && contributors != nil { var contributorInfos []*ContributorInfo for _, c := range contributors { + // get user info from committer email user, err := models.GetUserByEmail(c.Email) if err == nil { + // committer is system user, get info through user's primary email existedContributorInfo := getContributorInfo(contributorInfos,user.Email) if existedContributorInfo != nil { + // existed: same primary email, different committer name existedContributorInfo.CommitCnt += c.CommitCnt }else{ + // new committer info contributorInfos = append(contributorInfos, &ContributorInfo{ user, user.Email,c.CommitCnt, }) } } else { - contributorInfos = append(contributorInfos, &ContributorInfo{ - nil, c.Email,c.CommitCnt, - }) + // committer is not system user + existedContributorInfo := getContributorInfo(contributorInfos,c.Email) + if existedContributorInfo != nil { + // existed: same primary email, different committer name + existedContributorInfo.CommitCnt += c.CommitCnt + }else{ + contributorInfos = append(contributorInfos, &ContributorInfo{ + nil, c.Email,c.CommitCnt, + }) + } } } ctx.Data["ContributorInfo"] = contributorInfos From db6cf3ee40894e1c1d011756bf99a9578c435bc7 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Wed, 4 Aug 2021 16:14:15 +0800 Subject: [PATCH 10/17] fix left problem of 186 --- models/user_mail.go | 12 ++++++++++++ routers/user/auth.go | 9 +++++++++ routers/user/setting/profile.go | 12 ++++++++++++ 3 files changed, 33 insertions(+) mode change 100644 => 100755 models/user_mail.go mode change 100644 => 100755 routers/user/setting/profile.go diff --git a/models/user_mail.go b/models/user_mail.go old mode 100644 new mode 100755 index af9602e71..7244ec378 --- a/models/user_mail.go +++ b/models/user_mail.go @@ -80,6 +80,18 @@ func GetEmailAddressByID(uid, id int64) (*EmailAddress, error) { return email, nil } +// GetEmailAddressByIDAndEmail gets a user's email address by ID and email +func GetEmailAddressByIDAndEmail(uid int64, emailAddr string) (*EmailAddress, error) { + // User ID is required for security reasons + email := &EmailAddress{UID: uid, Email: emailAddr} + if has, err := x.Get(email); err != nil { + return nil, err + } else if !has { + return nil, nil + } + return email, nil +} + func isEmailActive(e Engine, email string, userID, emailID int64) (bool, error) { if len(email) == 0 { return true, nil diff --git a/routers/user/auth.go b/routers/user/auth.go index dd66fcb8b..13e338565 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -1266,6 +1266,15 @@ func Activate(ctx *context.Context) { log.Error("Error storing session: %v", err) } + email, err := models.GetEmailAddressByIDAndEmail(user.ID, user.Email) + if err != nil || email == nil{ + log.Error("GetEmailAddressByIDAndEmail failed", ctx.Data["MsgID"]) + } else { + if err := email.Activate(); err != nil { + log.Error("Activate failed: %v", err, ctx.Data["MsgID"]) + } + } + ctx.Flash.Success(ctx.Tr("auth.account_activated")) ctx.Redirect(setting.AppSubURL + "/") return diff --git a/routers/user/setting/profile.go b/routers/user/setting/profile.go old mode 100644 new mode 100755 index d6f25f913..a385f2cac --- a/routers/user/setting/profile.go +++ b/routers/user/setting/profile.go @@ -96,6 +96,18 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) { ctx.User.Location = form.Location ctx.User.Language = form.Language ctx.User.Description = form.Description + isUsed, err := models.IsEmailUsed(form.Email) + if err != nil { + ctx.ServerError("IsEmailUsed", err) + return + } + + if isUsed { + ctx.Flash.Error(ctx.Tr("form.email_been_used")) + ctx.Redirect(setting.AppSubURL + "/user/settings") + return + } + if err := models.UpdateUserSetting(ctx.User); err != nil { if _, ok := err.(models.ErrEmailAlreadyUsed); ok { ctx.Flash.Error(ctx.Tr("form.email_been_used")) From 374ae4611bdd2d1d26ff1687f2e0b0bc1f2870de Mon Sep 17 00:00:00 2001 From: OpenIhu Date: Wed, 4 Aug 2021 17:24:28 +0800 Subject: [PATCH 11/17] =?UTF-8?q?ContributorInfo=E8=B6=85=E8=BF=873?= =?UTF-8?q?=E4=B8=AA=E6=8A=98=E5=8F=A0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/home.tmpl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 7d632ea14..8065ce12d 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -193,13 +193,16 @@

贡献者 ({{len .ContributorInfo}})

- -
+ +
{{range .ContributorInfo}} - {{/*  {{.UserInfo.Name}}*/}} {{if .UserInfo}} {{else if .Email}} @@ -215,4 +218,12 @@
+ + {{template "base/footer" .}} From 4945ca4bdba7a96dce61778c72dfd28a5be9974e Mon Sep 17 00:00:00 2001 From: OpenIhu Date: Wed, 4 Aug 2021 21:28:16 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E8=B0=83=E6=95=B4ContributorInfo?= =?UTF-8?q?=E8=B6=85=E8=BF=8725=E4=B8=AA=E6=8A=98=E5=8F=A0=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E8=B0=83=E6=95=B4=E9=82=AE=E4=BB=B6=E8=81=94=E7=B3=BB?= =?UTF-8?q?=E8=80=85=E6=98=BE=E7=A4=BA=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/home.tmpl | 53 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 8065ce12d..a7eb085de 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -4,6 +4,48 @@ font-size: 1.0em; margin-bottom: 1.0rem; } +#contributorInfo > a:nth-child(n+25){ + display:none; +} +#contributorInfo > a{ + width: 2.0em; + float: left; + margin: .25em; +} +#contributorInfo > a.circular{ + height: 2.0em; + padding: 0; + overflow: hidden; + letter-spacing:1.0em; + text-indent: 0.6em; + line-height: 2.0em; + text-transform:capitalize; + color: #FFF; +} +#contributorInfo > a.circular:nth-child(9n+1){ + background-color: #00ADD8; +} +#contributorInfo > a.circular:nth-child(9n+2){ + background-color: #796218; +} +#contributorInfo > a.circular:nth-child(9n+3){ + background-color: #772c5a; +} +#contributorInfo > a.circular:nth-child(9n+4){ + background-color: #33225c; +} +#contributorInfo > a.circular:nth-child(9n+5){ + background-color: #146e5b; +} +#contributorInfo > a.circular:nth-child(9n+6){ + background-color: #26557c; +} +#contributorInfo > a.circular:nth-child(9n+7){ + background-color: #5c223a; +} +#contributorInfo > a.circular:nth-child(9n+8){ + background-color: #3f5720; +}
{{template "repo/header" .}} @@ -196,17 +238,12 @@ 全部 {{svg "octicon-chevron-right" 16}}
-
{{range .ContributorInfo}} {{if .UserInfo}} - + {{else if .Email}} - + {{.Email}} {{end}} {{end}}
@@ -222,7 +259,7 @@ From 29ed7e81bca9fb0c6dba0a8dd52837017fc530c4 Mon Sep 17 00:00:00 2001 From: OpenIhu Date: Wed, 4 Aug 2021 21:41:22 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E8=B0=83=E6=95=B4ContributorInfo?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E8=81=94=E7=B3=BB=E8=80=85=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/home.tmpl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index a7eb085de..75cee742e 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -23,28 +23,28 @@ color: #FFF; } #contributorInfo > a.circular:nth-child(9n+1){ - background-color: #00ADD8; + background-color: #4ccdec; } #contributorInfo > a.circular:nth-child(9n+2){ - background-color: #796218; + background-color: #e0b265; } #contributorInfo > a.circular:nth-child(9n+3){ - background-color: #772c5a; + background-color: #d884b7; } #contributorInfo > a.circular:nth-child(9n+4){ - background-color: #33225c; + background-color: #8c6bdc; } #contributorInfo > a.circular:nth-child(9n+5){ - background-color: #146e5b; + background-color: #3cb99f; } #contributorInfo > a.circular:nth-child(9n+6){ - background-color: #26557c; + background-color: #6995b9; } #contributorInfo > a.circular:nth-child(9n+7){ - background-color: #5c223a; + background-color: #ab91a7; } #contributorInfo > a.circular:nth-child(9n+8){ - background-color: #3f5720; + background-color: #bfd0aa; }
From b93808dddf02f318905d289c92607376efff06ff Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 5 Aug 2021 10:48:03 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=B8=E5=AE=A2?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=97=B6=EF=BC=8C=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=B8=BA=E7=A9=BA=E7=9A=84=E6=83=85=E5=86=B5=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 19 ++++++++++--------- routers/repo/dataset.go | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 830f193ee..6fa89420d 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -151,18 +151,19 @@ func DownloadUserIsOrgOrCollaboration(ctx *context.Context, attach *models.Attac log.Info("query repo error.") } else { repo.GetOwner() - if repo.Owner.IsOrganization() { - //log.Info("ower is org.") - if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { - log.Info("org user may visit the attach.") + if ctx.User != nil { + if repo.Owner.IsOrganization() { + if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { + log.Info("org user may visit the attach.") + return true + } + } + isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) + if isCollaborator { + log.Info("Collaborator user may visit the attach.") return true } } - isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) - if isCollaborator { - log.Info("Collaborator user may visit the attach.") - return true - } } } return false diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index bdadd2066..b2da4b8d8 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -32,13 +32,13 @@ func newFilterPrivateAttachments(ctx *context.Context, list []*models.Attachment repo.GetOwner() } permission := false - if repo.Owner.IsOrganization() { + if repo.Owner.IsOrganization() && ctx.User != nil { if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { log.Info("user is member of org.") permission = true } } - if !permission { + if !permission && ctx.User != nil { isCollaborator, _ := repo.IsCollaborator(ctx.User.ID) if isCollaborator { log.Info("Collaborator user may visit the attach.") From cafa013fa58fdfb95d1c45ec80f82c9a51310663 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 5 Aug 2021 11:32:04 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E5=BD=93=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E6=98=AF=E5=85=AC=E6=9C=89=E6=97=B6=EF=BC=8C=E4=B8=94=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=94=A8=E6=88=B7=E5=A6=82=E6=9E=9C=E8=83=BD=E7=9C=8B?= =?UTF-8?q?=E5=88=B0=EF=BC=8C=E9=82=A3=E4=B9=88=E5=B0=B1=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 6fa89420d..ed9f7c47e 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -177,7 +177,6 @@ func GetAttachment(ctx *context.Context) { ctx.ServerError("checkTypeCloudBrain failed", err) return } - attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) if err != nil { if models.IsErrAttachmentNotExist(err) { @@ -187,22 +186,19 @@ func GetAttachment(ctx *context.Context) { } return } - repository, unitType, err := attach.LinkedRepository() if err != nil { ctx.ServerError("LinkedRepository", err) return } - 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) && !DownloadUserIsOrgOrCollaboration(ctx, attach) { //We block if not the uploader + if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate && !DownloadUserIsOrgOrCollaboration(ctx, attach) { //We block if not the uploader ctx.Error(http.StatusNotFound) return } } else { //If we have the repository we check access - perm, err := models.GetUserRepoPermission(repository, ctx.User) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error()) @@ -213,7 +209,6 @@ func GetAttachment(ctx *context.Context) { return } } - dataSet, err := attach.LinkedDataSet() if err != nil { ctx.ServerError("LinkedDataSet", err) From eebd5aa32bac4540ac9ac1170c02f0ea30fe0f4d Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 5 Aug 2021 16:32:31 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=80=85=E4=B8=8D=E8=83=BD=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=20=E5=8D=8F=E4=BD=9C=E8=80=85=E4=B8=8A=E4=BC=A0=E7=9A=84?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E6=95=B0=E6=8D=AE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index ed9f7c47e..cdb73c8a0 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -152,6 +152,7 @@ func DownloadUserIsOrgOrCollaboration(ctx *context.Context, attach *models.Attac } else { repo.GetOwner() if ctx.User != nil { + if repo.Owner.IsOrganization() { if repo.Owner.IsUserPartOfOrg(ctx.User.ID) { log.Info("org user may visit the attach.") @@ -177,6 +178,7 @@ func GetAttachment(ctx *context.Context) { ctx.ServerError("checkTypeCloudBrain failed", err) return } + attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid")) if err != nil { if models.IsErrAttachmentNotExist(err) { @@ -186,22 +188,31 @@ func GetAttachment(ctx *context.Context) { } return } + repository, unitType, err := attach.LinkedRepository() if err != nil { ctx.ServerError("LinkedRepository", err) return } + dataSet, err := attach.LinkedDataSet() + + if repository == nil && dataSet != nil { + repository, _ = models.GetRepositoryByID(dataSet.RepoID) + unitType = models.UnitTypeDatasets + } + if repository == nil { //If not linked //if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate { //We block if not the uploader + //log.Info("ctx.IsSigned =" + fmt.Sprintf("%v", ctx.IsSigned)) if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) && attach.IsPrivate && !DownloadUserIsOrgOrCollaboration(ctx, attach) { //We block if not the uploader ctx.Error(http.StatusNotFound) return } } else { //If we have the repository we check access - perm, err := models.GetUserRepoPermission(repository, ctx.User) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error()) + perm, errPermission := models.GetUserRepoPermission(repository, ctx.User) + if errPermission != nil { + ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", errPermission.Error()) return } if !perm.CanRead(unitType) { @@ -209,12 +220,11 @@ func GetAttachment(ctx *context.Context) { return } } - dataSet, err := attach.LinkedDataSet() + //dataSet, err := attach.LinkedDataSet() if err != nil { ctx.ServerError("LinkedDataSet", err) return } - if dataSet != nil { isPermit, err := models.GetUserDataSetPermission(dataSet, ctx.User) if err != nil { From 495addb579311ca31b46398b34db55a1f766a5e4 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 5 Aug 2021 16:50:27 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E7=9A=84=E9=94=99=E8=AF=AF=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=BE=80=E4=B8=8A=E6=8F=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/attachment.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index cdb73c8a0..fea7a3384 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -195,6 +195,10 @@ func GetAttachment(ctx *context.Context) { return } dataSet, err := attach.LinkedDataSet() + if err != nil { + ctx.ServerError("LinkedDataSet", err) + return + } if repository == nil && dataSet != nil { repository, _ = models.GetRepositoryByID(dataSet.RepoID) @@ -220,11 +224,7 @@ func GetAttachment(ctx *context.Context) { return } } - //dataSet, err := attach.LinkedDataSet() - if err != nil { - ctx.ServerError("LinkedDataSet", err) - return - } + if dataSet != nil { isPermit, err := models.GetUserDataSetPermission(dataSet, ctx.User) if err != nil {