core

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package core defines the bootstrapped core application for identity, roles, and permissions.

Index

Constants

View Source
const (
	AdminEmail = "admin@localhost"
	AdminRole  = "System Administrator"
)

Variables

View Source
var App = app.Definition{
	Name:        "core",
	Title:       "Orjanda Core",
	Version:     "0.1.0",
	Description: "Core identity, role, and permission documents",
	Publisher:   "Orjanda Framework",
	Modules: []app.Module{
		{Name: "core", Title: "Core"},
	},
}

App is the app.Definition for Orjanda Core. See PRD §11 and TAD §4.

Functions

func Bootstrap

func Bootstrap(ctx context.Context, db dal.Database, reg schema.Registry) (string, error)

Bootstrap executes the first-run system administrator setup if no users exist. Returns (password, nil) if bootstrapped, or ("", nil) if already bootstrapped. Idempotent: does nothing on subsequent calls. The whole sequence runs inside a single transaction (REVIEW-2026-08-12 finding 12): the User-empty check and every insert share one write transaction, and the database enforces uniqueness on User.email / Role.role_name, so concurrent serve instances can never create duplicate admins. See TAD §4.2.

func RegisterUserHooks

func RegisterUserHooks(bus event.Bus)

RegisterUserHooks installs the core User lifecycle hooks. The stored Password value is a bcrypt hash (TAD §4.1, PRD §15.1): a plaintext password written through the Document Engine is hashed on before_save so the built-in login endpoint (api/auth.go) can verify it. Values that are already bcrypt hashes pass through untouched, so updates that re-send a stored hash are idempotent.

Call once per site with the site's EventBus. The hook is keyed by the docType name, so registration order relative to document registration does not matter.

Types

type Role

type Role struct {
	schema.BaseDocument
	RoleName string `oj:"required,unique"`
}

Role represents a system role definition. See TAD §4.1.

func (*Role) DocMeta

func (r *Role) DocMeta() schema.Meta

func (*Role) Get

func (r *Role) Get(field string) any

func (*Role) Set

func (r *Role) Set(field string, value any) orjerrors.Error

type RolePermission

type RolePermission struct {
	schema.BaseDocument
	Role    schema.Link `oj:"link=Role,required"`
	DocType string      `oj:"required"`
	Read    bool
	Write   bool
	Create  bool
	Delete  bool
	Submit  bool
}

RolePermission represents a granted set of CRUD/Submit permissions for a Role on a DocType. See TAD §4.1.

func (*RolePermission) DocMeta

func (rp *RolePermission) DocMeta() schema.Meta

func (*RolePermission) Get

func (rp *RolePermission) Get(field string) any

func (*RolePermission) Set

func (rp *RolePermission) Set(field string, value any) orjerrors.Error

type User

type User struct {
	schema.BaseDocument
	Email    string     `oj:"required,unique,format=email,searchable"`
	FullName string     `oj:"required,searchable"`
	Password string     `oj:"hidden"`
	Roles    []UserRole `oj:"child_table"`
	Active   bool       `oj:"default=true"`
}

User represents a system user account. See TAD §4.1.

func (*User) DocMeta

func (u *User) DocMeta() schema.Meta

func (*User) Get

func (u *User) Get(field string) any

func (*User) Set

func (u *User) Set(field string, value any) orjerrors.Error

type UserRole

type UserRole struct {
	schema.BaseChild
	Role schema.Link `oj:"link=Role,required"`
}

UserRole represents a role assigned to a User (child table). See TAD §4.1.

func (*UserRole) DocMeta

func (ur *UserRole) DocMeta() schema.Meta

func (*UserRole) Get

func (ur *UserRole) Get(field string) any

func (*UserRole) Set

func (ur *UserRole) Set(field string, value any) orjerrors.Error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL