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
}
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")
{ a.RoleName }
if a.Scope != "" {
· { a.Scope }
}
if v.CanManage {
}
}
if v.CanManage && !m.IsOwner {
{ i18n.T(ctx, "sso.action.edit") }
}
}
if v.CanManage {
@sectionHeading("members.invite")
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) {
}
templ RolesPage(p Page, me Me, v RolesView) {
@consoleShell(p, me) {
@settingsHeading("roles.title", "roles.intro")
if v.CanManage {
@sectionHeading("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 {
}
@sectionHeading("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
}
templ OrgSettingsPage(p Page, me Me, v OrgSettings) {
@consoleShell(p, me) {
@settingsHeading("org.title", "")
@sectionHeading("org.policy")
}
}
// 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 {