Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add team and collaborators permission adjustment logs #20724

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions models/admin/notice.go
Expand Up @@ -24,6 +24,8 @@ const (
NoticeRepository NoticeType = iota + 1
// NoticeTask type
NoticeTask
// Permission type
NoticePermission
)

// Notice represents a system notice for admin.
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions options/locale/locale_en-US.ini
Expand Up @@ -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 <a href="%s">%s</a>
Expand Down
15 changes: 15 additions & 0 deletions routers/web/org/teams.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}

Expand Down
20 changes: 20 additions & 0 deletions routers/web/repo/setting.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}

Expand All @@ -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",
})
Expand Down Expand Up @@ -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")
}

Expand All @@ -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",
})
Expand Down