diff --git a/models/admin/notice.go b/models/admin/notice.go index 4d385cf951fc..9d2480a60c06 100644 --- a/models/admin/notice.go +++ b/models/admin/notice.go @@ -24,6 +24,8 @@ const ( NoticeRepository NoticeType = iota + 1 // NoticeTask type NoticeTask + // Permission type + NoticePermission ) // Notice represents a system notice for admin. @@ -61,6 +63,13 @@ func CreateRepositoryNotice(desc string, args ...interface{}) error { return CreateNotice(db.DefaultContext, NoticeRepository, desc, args...) } +// CreatePermissionNotice creates new notice with type NoticePermission. +func CreatePermissionNotice(desc string, args ...interface{}) { + if err := CreateNotice(db.DefaultContext, NoticePermission, desc, args...); err != nil { + log.Error("CreatePermissionNotice: %v", err) + } +} + // RemoveAllWithNotice removes all directories in given path and // creates a system notice when error occurs. func RemoveAllWithNotice(ctx context.Context, title, path string) { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 426521e4ee21..9f25b577584c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2955,6 +2955,17 @@ notices.type_2 = Task notices.desc = Description notices.op = Op. notices.delete_success = The system notices have been deleted. +notices.addusertoteam = %s added user %s to %s/%s team +notices.removeuserfromteam = %s removed user %s from %s/%s team +notices.addteamtorepo = %s added team %s to %s/%s repository +notices.removeteamfromrepo = %s removed team %s from %s/%s repository +notices.addusertorepo = %s added user %s to %s/%s +notices.removeuserfromrepo = %s removed user %s from %s/%s +notices.addrepototeam = %s added repository %s/%s to %s +notices.removerepofromteam = %s removed repository %s/%s from %s +notices.addallrepostoteam = %s added all repository to %s/%s +notices.removeallreposfromteam = %s removed all repository from %s/%s +notices.adjustteampermissions = %s adjust team %s/%s permissions %v [action] create_repo = created repository %s diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 284fb096f340..209465b92ac4 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -13,6 +13,7 @@ import ( "strings" "code.gitea.io/gitea/models" + admin_model "code.gitea.io/gitea/models/admin" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" @@ -114,6 +115,10 @@ func TeamsAction(ctx *context.Context) { map[string]interface{}{ "redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName), }) + + u, _ := user_model.GetUserByID(uid) + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.removeuserfromteam"), ctx.Doer.GetDisplayName(), u.GetDisplayName(), ctx.Org.Organization.Name, ctx.Org.Team.Name) + return case "add": if !ctx.Org.IsOwner { @@ -145,6 +150,8 @@ func TeamsAction(ctx *context.Context) { err = models.AddTeamMember(ctx.Org.Team, u.ID) } + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.addusertoteam"), ctx.Doer.GetDisplayName(), u.GetDisplayName(), ctx.Org.Organization.Name, ctx.Org.Team.Name) + page = "team" } @@ -195,12 +202,17 @@ func TeamsRepoAction(ctx *context.Context) { return } err = models.AddRepository(ctx.Org.Team, repo) + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.addrepototeam"), ctx.Doer.GetDisplayName(), ctx.Org.Organization.Name, repoName, ctx.Org.Team.Name) case "remove": err = models.RemoveRepository(ctx.Org.Team, ctx.FormInt64("repoid")) + repoName, _ := repo_model.GetRepositoryByID(ctx.FormInt64("repoid")) + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.removerepofromteam"), ctx.Doer.GetDisplayName(), ctx.Org.Organization.Name, repoName.Name, ctx.Org.Team.Name) case "addall": err = models.AddAllRepositories(ctx.Org.Team) + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.addallrepostoteam"), ctx.Doer.GetDisplayName(), ctx.Org.Organization.Name, ctx.Org.Team.Name) case "removeall": err = models.RemoveAllRepositories(ctx.Org.Team) + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.removeallreposfromteam"), ctx.Doer.GetDisplayName(), ctx.Org.Organization.Name, ctx.Org.Team.Name) } if err != nil { @@ -455,6 +467,9 @@ func EditTeamPost(ctx *context.Context) { } return } + + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.adjustteampermissions"), ctx.Doer.GetDisplayName(), ctx.Org.Organization.Name, ctx.Org.Team.Name, unitPerms) + ctx.Redirect(ctx.Org.OrgLink + "/teams/" + url.PathEscape(t.LowerName)) } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index a59824cecdb4..32c1fe1508c3 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -14,6 +14,8 @@ import ( "strings" "time" + admin_model "code.gitea.io/gitea/models/admin" + "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/db" @@ -923,6 +925,10 @@ func CollaborationPost(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success")) + + if doer := ctx.Doer; doer != nil { + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.addusertorepo"), doer.GetDisplayName(), name, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + } ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath()) } @@ -944,6 +950,10 @@ func DeleteCollaboration(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success")) } + u, _ := user_model.GetUserByID(ctx.FormInt64("id")) + if doer := ctx.Doer; doer != nil { + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.removeuserfromrepo"), doer.GetDisplayName(), u.Name, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + } ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/settings/collaboration", }) @@ -992,6 +1002,11 @@ func AddTeamPost(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.settings.add_team_success")) + + if doer := ctx.Doer; doer != nil { + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.addteamtorepo"), doer.GetDisplayName(), name, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + } + ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration") } @@ -1015,6 +1030,11 @@ func DeleteTeam(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.settings.remove_team_success")) + + if doer := ctx.Doer; doer != nil { + admin_model.CreatePermissionNotice(ctx.Tr("admin.notices.removeteamfromrepo"), doer.GetDisplayName(), team.Name, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + } + ctx.JSON(http.StatusOK, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/settings/collaboration", })