Skip to content

Add build number to workspace_build audit logs #5267

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

Merged
merged 15 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added support for group, template, user links
  • Loading branch information
Kira-Pilot committed Nov 28, 2022
commit ddc0dc04b90e90be62158837389e551d7350a10f
17 changes: 6 additions & 11 deletions coderd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,12 @@ type AdditionalFields struct {

func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAuditLogsOffsetRow) string {
switch alog.ResourceType {
case database.ResourceTypeOrganization:
return ""
case database.ResourceTypeTemplate:
return ""
case database.ResourceTypeTemplateVersion:
return ""
return fmt.Sprintf("/templates/%s",
alog.ResourceTarget)
case database.ResourceTypeUser:
return ""
return fmt.Sprintf("/users?filter=%s",
alog.ResourceTarget)
case database.ResourceTypeWorkspace:
return fmt.Sprintf("/@%s/%s",
alog.UserUsername.String, alog.ResourceTarget)
Expand All @@ -232,12 +230,9 @@ func (api *API) auditLogResourceLink(ctx context.Context, alog database.GetAudit
}
return fmt.Sprintf("/@%s/%s/builds/%s",
alog.UserUsername.String, additionalFields.WorkspaceName, additionalFields.BuildNumber)
case database.ResourceTypeGitSshKey:
return ""
case database.ResourceTypeApiKey:
return ""
case database.ResourceTypeGroup:
return ""
return fmt.Sprintf("/groups/%s",
alog.ResourceID)
default:
return ""
}
Expand Down
20 changes: 13 additions & 7 deletions site/src/components/AuditLogRow/AuditLogRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import { Link as RouterLink } from "react-router-dom"
import i18next from "i18next"
import Link from "@material-ui/core/Link"

const determineResourceLink = (auditLog: AuditLog): string => {
const determineResourceLink = (auditLog: AuditLog): JSX.Element | undefined => {
const { t } = i18next
let linkTarget = auditLog.resource_target.trim()
const linkTarget = auditLog.resource_target.trim()

if (auditLog.resource_type === "workspace_build") {
linkTarget = t("auditLog:table.logRow.buildTarget")
return <>{t("auditLog:table.logRow.buildTarget")}</>
} else if (auditLog.resource_type === "git_ssh_key") {
return
} else {
return <strong>{linkTarget}</strong>
}

return linkTarget
}

export const readableActionMessage = (auditLog: AuditLog): string => {
Expand Down Expand Up @@ -125,16 +127,20 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
>
<span>
{readableActionMessage(auditLog)}{" "}
{auditLog.resource_link && (
{auditLog.resource_link ? (
<Link component={RouterLink} to={auditLog.resource_link}>
{determineResourceLink(auditLog)}
</Link>
) : (
<strong>{determineResourceLink(auditLog)}</strong>
)}
{auditLog.resource_type === "workspace_build" &&
auditLog.additional_fields.workspaceName && (
<>
{t("auditLog:table.logRow.buildFriendlyString")}
{auditLog.additional_fields.workspaceName}
<strong>
{auditLog.additional_fields.workspaceName}
</strong>
</>
)}
</span>
Expand Down