package web import ( "slices" "strconv" "git.zb-server.de/ZB-Server/uptimesebi/internal/auth" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" ) // Role is a built-in or custom role. type Role struct { ID string Name string BuiltIn bool Permissions []string } // Assignment is one role a member holds. type Assignment struct { ID string RoleName string // Scope is empty for organization-wide assignments. Scope string } // Member is a row on the members page. type Member struct { UserID string Email string DisplayName string IsOwner bool Assignments []Assignment } // PendingInvite is an invitation that was not accepted yet. type PendingInvite struct { ID string Email string RoleName string } // MembersView is the data of the members page. type MembersView struct { Members []Member Roles []Role Invitations []PendingInvite CanManage bool // Scopes are the resources an assignment can be limited to; values are // ":". Scopes []ScopeOption } // ScopeOption is a resource an assignment can be limited to. type ScopeOption struct { Value string Label string } templ settingsHeading(titleID, introID string) {

{ i18n.T(ctx, titleID) }

if introID != "" {

{ i18n.T(ctx, introID) }

} } templ sectionHeading(id string) {

{ i18n.T(ctx, id) }

} templ roleSelect(roles []Role, name string) { } templ MembersPage(p Page, me Me, v MembersView) { @consoleShell(p, me) { @settingsHeading("members.title", "members.intro") for _, m := range v.Members { }
{ i18n.T(ctx, "auth.field.email") } { i18n.T(ctx, "members.roles") }
{ m.Email } if m.DisplayName != "" { { m.DisplayName } } if m.IsOwner { { i18n.T(ctx, "members.owner") } }
    for _, a := range m.Assignments {
  • { a.RoleName } if a.Scope != "" { · { a.Scope } } if v.CanManage { }
  • }
if v.CanManage && !m.IsOwner {
{ i18n.T(ctx, "sso.action.edit") }
@formError() @roleSelect(v.Roles, "role_id") @submit(i18n.T(ctx, "members.assign"))
}
if v.CanManage {
@sectionHeading("members.invite")
@formError() @field(i18n.T(ctx, "auth.field.email"), "email", "email", "off", true) @submit(i18n.T(ctx, "members.invite_submit"))
if len(v.Invitations) > 0 {
@sectionHeading("members.pending")
    for _, inv := range v.Invitations {
  • { inv.Email } · { inv.RoleName }
  • }
}
} } } // RolesView is the data of the roles page. type RolesView struct { Roles []Role Permissions []string // Grantable lists the permissions the viewer may put into a role. Grantable []string CanManage bool } templ permissionChecks(all, grantable, checked []string) {
for _, perm := range all { }
} templ RolesPage(p Page, me Me, v RolesView) { @consoleShell(p, me) { @settingsHeading("roles.title", "roles.intro")
for _, r := range v.Roles {

{ r.Name } if r.BuiltIn { { i18n.T(ctx, "roles.built_in") } }

if v.CanManage && !r.BuiltIn { }
if v.CanManage && !r.BuiltIn {
@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", r.Name, "", true) @permissionChecks(v.Permissions, v.Grantable, r.Permissions) @submit(i18n.T(ctx, "common.save"))
} else {
    for _, perm := range r.Permissions {
  • { i18n.T(ctx, "perm."+perm) }
  • }
}
}
if v.CanManage {
@sectionHeading("roles.create")
@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true) @permissionChecks(v.Permissions, v.Grantable, nil) @submit(i18n.T(ctx, "roles.create"))
} } } // Token is a row on the tokens page. type Token struct { ID string Name string Prefix string UserEmail string Permissions []string CreatedAt string ExpiresAt string LastUsedAt string } // TokensView is the data of the tokens page. type TokensView struct { Tokens []Token Grantable []string // ShowOwner is set when the viewer oversees all tokens of the org. ShowOwner bool // MaxDays is the org's token lifetime limit, 0 if none. MaxDays int // ExpiryDays are the lifetimes offered when creating a token; 0 means // no expiry. ExpiryDays []int } templ TokensPage(p Page, me Me, v TokensView) { @consoleShell(p, me) { if v.ShowOwner { @settingsHeading("tokens.title", "tokens.intro_all") } else { @settingsHeading("tokens.title", "tokens.intro") } if v.MaxDays > 0 {

{ i18n.T(ctx, "tokens.policy", "Count", v.MaxDays) }

} if len(v.Tokens) > 0 { if v.ShowOwner { } for _, t := range v.Tokens { if v.ShowOwner { } }
{ i18n.T(ctx, "sso.field.name") }{ i18n.T(ctx, "tokens.owner") }{ i18n.T(ctx, "tokens.permissions") } { i18n.T(ctx, "tokens.created") } { i18n.T(ctx, "tokens.expires") } { i18n.T(ctx, "tokens.last_used") }
{ t.Name } { t.Prefix }…{ t.UserEmail }
    for _, perm := range t.Permissions {
  • { i18n.T(ctx, "perm."+perm) }
  • }
{ t.CreatedAt } { t.ExpiresAt } { t.LastUsedAt }
}
@sectionHeading("tokens.create") @tokenUsage()
@formError() @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true) @permissionChecks(v.Grantable, v.Grantable, nil) @submit(i18n.T(ctx, "tokens.create"))
} } // OrgSettings is the data of the organization settings page. type OrgSettings struct { RequireTOTP bool RequireSSO bool // TokenMaxDays is 0 when API token lifetime is unlimited. TokenMaxDays int // CheckTypes are the types the platform offers, enabled unless the // organization switched them off. CheckTypes []CheckTypeOption Usage UsageView } templ OrgSettingsPage(p Page, me Me, v OrgSettings) { @consoleShell(p, me) { @settingsHeading("org.title", "")
@sectionHeading("org.policy")
@formError() @checkbox(i18n.T(ctx, "org.require_totp"), "require_totp", v.RequireTOTP)

{ i18n.T(ctx, "org.require_totp_hint") }

@checkbox(i18n.T(ctx, "org.require_sso"), "require_sso", v.RequireSSO)

{ i18n.T(ctx, "org.require_sso_hint") }

{ i18n.T(ctx, "org.token_max_days_hint") }

@submit(i18n.T(ctx, "common.save"))
@usageSection(v.Usage) @checkTypesSection(v.CheckTypes, "/org/check-types", "/settings/org", "org.check_types_intro") @orgDataSection(me) } } // Invitation is the data of the invitation landing page. type Invitation struct { Token string Valid bool OrgName string RoleName string Email string SignedInAs string AccountExists bool } templ InvitationPage(p Page, v Invitation) { @authShell(p) { if !v.Valid {

{ i18n.T(ctx, "error.invitation_invalid") }

} else {

{ i18n.T(ctx, "invite.summary", "Org", v.OrgName, "Role", v.RoleName) }

{ v.Email }

switch { case v.SignedInAs == v.Email:
@formError() @submit(i18n.T(ctx, "invite.accept"))
case v.SignedInAs != "":

{ i18n.T(ctx, "error.invitation_email_mismatch") }

case v.AccountExists: { i18n.T(ctx, "invite.sign_in") } default:
@formError() @field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false) @field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true) @submit(i18n.T(ctx, "invite.create_account"))
} } } } func maxDaysValue(d int) string { if d == 0 { return "" } return strconv.Itoa(d) } // tokenUsage explains how to send a token and links the API documentation. templ tokenUsage() {

{ i18n.T(ctx, "tokens.usage") } Authorization: Bearer ust_… · { i18n.T(ctx, "apidocs.title") }

}