MM-51321 Refactor audit log application. (#22481)
* Refactor audit log application. * Fix incorrect API Usage for Auditing * Fixups. * Rename Object audit to Auditable. Some small fixes. --------- Co-authored-by: Daniel Schalla <daniel@schalla.me>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9a38a52392
Коммит
7804debb7f
@@ -54,6 +54,14 @@ type BotPatch struct {
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
func (b *BotPatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"username": b.Username,
|
||||
"display_name": b.DisplayName,
|
||||
"description": b.Description,
|
||||
}
|
||||
}
|
||||
|
||||
// BotGetOptions acts as a filter on bulk bot fetching queries.
|
||||
type BotGetOptions struct {
|
||||
OwnerId string
|
||||
|
||||
@@ -142,6 +142,13 @@ type ChannelModerationPatch struct {
|
||||
Roles *ChannelModeratedRolesPatch `json:"roles"`
|
||||
}
|
||||
|
||||
func (c *ChannelModerationPatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"name": c.Name,
|
||||
"roles": c.Roles,
|
||||
}
|
||||
}
|
||||
|
||||
type ChannelModeratedRolesPatch struct {
|
||||
Guests *bool `json:"guests"`
|
||||
Members *bool `json:"members"`
|
||||
|
||||
@@ -59,6 +59,21 @@ type FileInfo struct {
|
||||
Archived bool `json:"archived"`
|
||||
}
|
||||
|
||||
func (fi *FileInfo) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": fi.Id,
|
||||
"creator_id": fi.CreatorId,
|
||||
"post_id": fi.PostId,
|
||||
"channel_id": fi.ChannelId,
|
||||
"create_at": fi.CreateAt,
|
||||
"update_at": fi.UpdateAt,
|
||||
"delete_at": fi.DeleteAt,
|
||||
"name": fi.Name,
|
||||
"extension": fi.Extension,
|
||||
"size": fi.Size,
|
||||
}
|
||||
}
|
||||
|
||||
func (fi *FileInfo) PreSave() {
|
||||
if fi.Id == "" {
|
||||
fi.Id = NewId()
|
||||
|
||||
@@ -66,6 +66,21 @@ type GroupWithUserIds struct {
|
||||
UserIds []string `json:"user_ids"`
|
||||
}
|
||||
|
||||
func (group *GroupWithUserIds) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": group.Id,
|
||||
"source": group.Source,
|
||||
"remote_id": group.RemoteId,
|
||||
"create_at": group.CreateAt,
|
||||
"update_at": group.UpdateAt,
|
||||
"delete_at": group.DeleteAt,
|
||||
"has_syncables": group.HasSyncables,
|
||||
"member_count": group.MemberCount,
|
||||
"allow_reference": group.AllowReference,
|
||||
"user_ids": group.UserIds,
|
||||
}
|
||||
}
|
||||
|
||||
type GroupWithSchemeAdmin struct {
|
||||
Group
|
||||
SchemeAdmin *bool `db:"SyncableSchemeAdmin" json:"scheme_admin,omitempty"`
|
||||
@@ -138,6 +153,12 @@ type GroupModifyMembers struct {
|
||||
UserIds []string `json:"user_ids"`
|
||||
}
|
||||
|
||||
func (group *GroupModifyMembers) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"user_ids": group.UserIds,
|
||||
}
|
||||
}
|
||||
|
||||
func (group *Group) Patch(patch *GroupPatch) {
|
||||
if patch.Name != nil {
|
||||
group.Name = patch.Name
|
||||
|
||||
@@ -153,6 +153,13 @@ type GroupSyncablePatch struct {
|
||||
SchemeAdmin *bool `json:"scheme_admin"`
|
||||
}
|
||||
|
||||
func (syncable *GroupSyncablePatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"auto_add": syncable.AutoAdd,
|
||||
"scheme_admin": syncable.SchemeAdmin,
|
||||
}
|
||||
}
|
||||
|
||||
func (syncable *GroupSyncable) Patch(patch *GroupSyncablePatch) {
|
||||
if patch.AutoAdd != nil {
|
||||
syncable.AutoAdd = *patch.AutoAdd
|
||||
|
||||
@@ -13,6 +13,13 @@ type GuestsInvite struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (i *GuestsInvite) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"emails": i.Emails,
|
||||
"channels": i.Channels,
|
||||
}
|
||||
}
|
||||
|
||||
// IsValid validates the user and returns an error if it isn't configured
|
||||
// correctly.
|
||||
func (i *GuestsInvite) IsValid() *AppError {
|
||||
|
||||
@@ -14,6 +14,13 @@ type MemberInvite struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (i *MemberInvite) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"emails": i.Emails,
|
||||
"channel_ids": i.ChannelIds,
|
||||
}
|
||||
}
|
||||
|
||||
// IsValid validates that the invitation info is loaded correctly and with the correct structure
|
||||
func (i *MemberInvite) IsValid() *AppError {
|
||||
if len(i.Emails) == 0 {
|
||||
|
||||
@@ -13,6 +13,12 @@ type CompleteOnboardingRequest struct {
|
||||
InstallPlugins []string `json:"install_plugins"` // InstallPlugins is a list of plugins to be installed
|
||||
}
|
||||
|
||||
func (r *CompleteOnboardingRequest) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"install_plugins": r.InstallPlugins,
|
||||
}
|
||||
}
|
||||
|
||||
// CompleteOnboardingRequest decodes a json-encoded request from the given io.Reader.
|
||||
func CompleteOnboardingRequestFromReader(reader io.Reader) (*CompleteOnboardingRequest, error) {
|
||||
var r *CompleteOnboardingRequest
|
||||
|
||||
@@ -41,6 +41,19 @@ type RemoteCluster struct {
|
||||
CreatorId string `json:"creator_id"`
|
||||
}
|
||||
|
||||
func (rc *RemoteCluster) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"remote_id": rc.RemoteId,
|
||||
"remote_team_id": rc.RemoteTeamId,
|
||||
"name": rc.Name,
|
||||
"display_name": rc.DisplayName,
|
||||
"site_url": rc.SiteURL,
|
||||
"create_at": rc.CreateAt,
|
||||
"last_ping_at": rc.LastPingAt,
|
||||
"creator_id": rc.CreatorId,
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RemoteCluster) PreSave() {
|
||||
if rc.RemoteId == "" {
|
||||
rc.RemoteId = NewId()
|
||||
@@ -154,6 +167,13 @@ type RemoteClusterFrame struct {
|
||||
Msg RemoteClusterMsg `json:"msg"`
|
||||
}
|
||||
|
||||
func (f *RemoteClusterFrame) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"remote_id": f.RemoteId,
|
||||
"msg": f.Msg,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *RemoteClusterFrame) IsValid() *AppError {
|
||||
if !IsValidId(f.RemoteId) {
|
||||
return NewAppError("RemoteClusterFrame.IsValid", "api.remote_cluster.invalid_id.app_error", nil, "RemoteId="+f.RemoteId, http.StatusBadRequest)
|
||||
|
||||
@@ -437,6 +437,12 @@ type RolePatch struct {
|
||||
Permissions *[]string `json:"permissions"`
|
||||
}
|
||||
|
||||
func (r *RolePatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"permissions": r.Permissions,
|
||||
}
|
||||
}
|
||||
|
||||
type RolePermissions struct {
|
||||
RoleID string
|
||||
Permissions []string
|
||||
|
||||
@@ -68,10 +68,24 @@ type SchemePatch struct {
|
||||
Description *string `json:"description"`
|
||||
}
|
||||
|
||||
func (scheme *SchemePatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"name": scheme.Name,
|
||||
"display_name": scheme.DisplayName,
|
||||
"description": scheme.Description,
|
||||
}
|
||||
}
|
||||
|
||||
type SchemeIDPatch struct {
|
||||
SchemeID *string `json:"scheme_id"`
|
||||
}
|
||||
|
||||
func (p *SchemeIDPatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"scheme_id": p.SchemeID,
|
||||
}
|
||||
}
|
||||
|
||||
// SchemeConveyor is used for importing and exporting a Scheme and its associated Roles.
|
||||
type SchemeConveyor struct {
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -70,7 +70,6 @@ func (s *Session) Auditable() map[string]interface{} {
|
||||
"is_oauth": s.IsOAuth,
|
||||
"expired_notify": s.ExpiredNotify,
|
||||
"local": s.Local,
|
||||
// TODO: props and members?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,15 @@ type SwitchRequest struct {
|
||||
LdapLoginId string `json:"ldap_id"`
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"current_service": o.CurrentService,
|
||||
"new_service": o.NewService,
|
||||
"email": o.Email,
|
||||
"ldap_login_id": o.LdapLoginId,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *SwitchRequest) EmailToOAuth() bool {
|
||||
return o.CurrentService == UserAuthServiceEmail &&
|
||||
(o.NewService == UserAuthServiceSaml ||
|
||||
|
||||
@@ -70,6 +70,14 @@ type TeamPatch struct {
|
||||
CloudLimitsArchived *bool `json:"cloud_limits_archived"`
|
||||
}
|
||||
|
||||
func (o *TeamPatch) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"allow_open_invite": o.AllowOpenInvite,
|
||||
"group_constrained": o.GroupConstrained,
|
||||
"cloud_limits_archived": o.CloudLimitsArchived,
|
||||
}
|
||||
}
|
||||
|
||||
type TeamForExport struct {
|
||||
Team
|
||||
SchemeName *string
|
||||
|
||||
@@ -47,6 +47,19 @@ type UploadSession struct {
|
||||
ReqFileId string `json:"req_file_id"`
|
||||
}
|
||||
|
||||
func (us *UploadSession) Auditable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"id": us.Id,
|
||||
"type": us.Type,
|
||||
"user_id": us.UserId,
|
||||
"channel_id": us.ChannelId,
|
||||
"filename": us.Filename,
|
||||
"file_size": us.FileSize,
|
||||
"remote_id": us.RemoteId,
|
||||
"ReqFileId": us.ReqFileId,
|
||||
}
|
||||
}
|
||||
|
||||
// PreSave is a utility function used to fill required information.
|
||||
func (us *UploadSession) PreSave() {
|
||||
if us.Id == "" {
|
||||
|
||||
Ссылка в новой задаче
Block a user