feat: add organization details to audit log response (#13961)

* Allow creating test audits with nil org

Not all audit entries have organization IDs, so this will allow us to
test those cases.

* Add organization details to audit log queries

* Add organization to audit log response

This replaces the old ID.  This is a breaking change but organizations
were not being used before.
This commit is contained in:
Asher
2024-07-22 13:28:44 -08:00
committed by GitHub
parent 38c7dcda94
commit a8e6e89f65
16 changed files with 348 additions and 120 deletions
+12 -8
View File
@@ -125,14 +125,13 @@ type AuditDiffField struct {
}
type AuditLog struct {
ID uuid.UUID `json:"id" format:"uuid"`
RequestID uuid.UUID `json:"request_id" format:"uuid"`
Time time.Time `json:"time" format:"date-time"`
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
IP netip.Addr `json:"ip"`
UserAgent string `json:"user_agent"`
ResourceType ResourceType `json:"resource_type"`
ResourceID uuid.UUID `json:"resource_id" format:"uuid"`
ID uuid.UUID `json:"id" format:"uuid"`
RequestID uuid.UUID `json:"request_id" format:"uuid"`
Time time.Time `json:"time" format:"date-time"`
IP netip.Addr `json:"ip"`
UserAgent string `json:"user_agent"`
ResourceType ResourceType `json:"resource_type"`
ResourceID uuid.UUID `json:"resource_id" format:"uuid"`
// ResourceTarget is the name of the resource.
ResourceTarget string `json:"resource_target"`
ResourceIcon string `json:"resource_icon"`
@@ -144,6 +143,11 @@ type AuditLog struct {
ResourceLink string `json:"resource_link"`
IsDeleted bool `json:"is_deleted"`
// Deprecated: Use 'organization.id' instead.
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
Organization *MinimalOrganization `json:"organization,omitempty"`
User *User `json:"user"`
}
+10 -6
View File
@@ -39,18 +39,22 @@ func ProvisionerTypeValid[T ProvisionerType | string](pt T) error {
}
}
// Organization is the JSON representation of a Coder organization.
type Organization struct {
type MinimalOrganization struct {
ID uuid.UUID `table:"id" json:"id" validate:"required" format:"uuid"`
Name string `table:"name,default_sort" json:"name"`
DisplayName string `table:"display_name" json:"display_name"`
Description string `table:"description" json:"description"`
CreatedAt time.Time `table:"created_at" json:"created_at" validate:"required" format:"date-time"`
UpdatedAt time.Time `table:"updated_at" json:"updated_at" validate:"required" format:"date-time"`
IsDefault bool `table:"default" json:"is_default" validate:"required"`
Icon string `table:"icon" json:"icon"`
}
// Organization is the JSON representation of a Coder organization.
type Organization struct {
MinimalOrganization `table:"m,recursive_inline"`
Description string `table:"description" json:"description"`
CreatedAt time.Time `table:"created_at" json:"created_at" validate:"required" format:"date-time"`
UpdatedAt time.Time `table:"updated_at" json:"updated_at" validate:"required" format:"date-time"`
IsDefault bool `table:"default" json:"is_default" validate:"required"`
}
func (o Organization) HumanName() string {
if o.DisplayName == "" {
return o.Name