mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: indicate when workspace builds are stopped/started by Coder (#5813)
* feat: indicate when workspace_builds are stopped/started by Coder * added translattion * added json tags and adjust type
This commit is contained in:
@ -180,8 +180,9 @@ func (api *API) convertAuditLogs(ctx context.Context, dblogs []database.GetAudit
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdditionalFields struct {
|
type AdditionalFields struct {
|
||||||
WorkspaceName string
|
WorkspaceName string `json:"workspace_name"`
|
||||||
BuildNumber string
|
BuildNumber string `json:"build_number"`
|
||||||
|
BuildReason database.BuildReason `json:"build_reason"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
|
func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogsOffsetRow) codersdk.AuditLog {
|
||||||
@ -219,6 +220,7 @@ func (api *API) convertAuditLog(ctx context.Context, dblog database.GetAuditLogs
|
|||||||
resourceInfo := map[string]string{
|
resourceInfo := map[string]string{
|
||||||
"workspaceName": "unknown",
|
"workspaceName": "unknown",
|
||||||
"buildNumber": "unknown",
|
"buildNumber": "unknown",
|
||||||
|
"buildReason": "unknown",
|
||||||
}
|
}
|
||||||
dblog.AdditionalFields, err = json.Marshal(resourceInfo)
|
dblog.AdditionalFields, err = json.Marshal(resourceInfo)
|
||||||
api.Logger.Error(ctx, "marshal additional fields", slog.Error(err))
|
api.Logger.Error(ctx, "marshal additional fields", slog.Error(err))
|
||||||
@ -262,8 +264,8 @@ func auditLogDescription(alog database.GetAuditLogsOffsetRow, additionalFields A
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Strings for starting/stopping workspace builds follow the below format:
|
// Strings for starting/stopping workspace builds follow the below format:
|
||||||
// "{user} started build #{build_number} for workspace {target}"
|
// "{user | 'Coder automatically'} started build #{build_number} for workspace {target}"
|
||||||
// where target is a workspace instead of a workspace build
|
// where target is a workspace (name) instead of a workspace build
|
||||||
// passed in on the FE via AuditLog.AdditionalFields rather than derived in request.go:35
|
// passed in on the FE via AuditLog.AdditionalFields rather than derived in request.go:35
|
||||||
if alog.ResourceType == database.ResourceTypeWorkspaceBuild && alog.Action != database.AuditActionDelete {
|
if alog.ResourceType == database.ResourceTypeWorkspaceBuild && alog.Action != database.AuditActionDelete {
|
||||||
if len(additionalFields.BuildNumber) == 0 {
|
if len(additionalFields.BuildNumber) == 0 {
|
||||||
|
@ -550,6 +550,7 @@ func (server *Server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*p
|
|||||||
buildResourceInfo := map[string]string{
|
buildResourceInfo := map[string]string{
|
||||||
"workspaceName": workspace.Name,
|
"workspaceName": workspace.Name,
|
||||||
"buildNumber": strconv.FormatInt(int64(build.BuildNumber), 10),
|
"buildNumber": strconv.FormatInt(int64(build.BuildNumber), 10),
|
||||||
|
"buildReason": fmt.Sprintf("%v", build.Reason),
|
||||||
}
|
}
|
||||||
|
|
||||||
wriBytes, err := json.Marshal(buildResourceInfo)
|
wriBytes, err := json.Marshal(buildResourceInfo)
|
||||||
@ -799,6 +800,7 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
|
|||||||
buildResourceInfo := map[string]string{
|
buildResourceInfo := map[string]string{
|
||||||
"workspaceName": workspace.Name,
|
"workspaceName": workspace.Name,
|
||||||
"buildNumber": strconv.FormatInt(int64(workspaceBuild.BuildNumber), 10),
|
"buildNumber": strconv.FormatInt(int64(workspaceBuild.BuildNumber), 10),
|
||||||
|
"buildReason": fmt.Sprintf("%v", workspaceBuild.Reason),
|
||||||
}
|
}
|
||||||
|
|
||||||
wriBytes, err := json.Marshal(buildResourceInfo)
|
wriBytes, err := json.Marshal(buildResourceInfo)
|
||||||
|
@ -12,10 +12,17 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
|
|||||||
const { t } = i18next
|
const { t } = i18next
|
||||||
|
|
||||||
let target = auditLog.resource_target.trim()
|
let target = auditLog.resource_target.trim()
|
||||||
|
let user = auditLog.user?.username.trim()
|
||||||
|
|
||||||
// audit logs with a resource_type of workspace build use workspace name as a target
|
|
||||||
if (auditLog.resource_type === "workspace_build") {
|
if (auditLog.resource_type === "workspace_build") {
|
||||||
|
// audit logs with a resource_type of workspace build use workspace name as a target
|
||||||
target = auditLog.additional_fields.workspaceName.trim()
|
target = auditLog.additional_fields.workspaceName.trim()
|
||||||
|
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
|
||||||
|
user =
|
||||||
|
auditLog.additional_fields.buildReason &&
|
||||||
|
auditLog.additional_fields.buildReason !== "initiator"
|
||||||
|
? t("auditLog:table.logRow.buildReason")
|
||||||
|
: auditLog.user?.username.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSH key entries have no links
|
// SSH key entries have no links
|
||||||
@ -30,7 +37,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const truncatedDescription = auditLog.description
|
const truncatedDescription = auditLog.description
|
||||||
.replace("{user}", `${auditLog.user?.username.trim()}`)
|
.replace("{user}", `${user}`)
|
||||||
.replace("{target}", "")
|
.replace("{target}", "")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
"os": "OS: ",
|
"os": "OS: ",
|
||||||
"browser": "Browser: ",
|
"browser": "Browser: ",
|
||||||
"notAvailable": "Not available",
|
"notAvailable": "Not available",
|
||||||
"onBehalfOf": " on behalf of {{owner}}"
|
"onBehalfOf": " on behalf of {{owner}}",
|
||||||
|
"buildReason": "Coder automatically"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"paywall": {
|
"paywall": {
|
||||||
|
Reference in New Issue
Block a user