Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
136 lines
3.7 KiB
Go
136 lines
3.7 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: roles.sql
|
|
|
|
package organization
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const createRoleAssignment = `-- name: CreateRoleAssignment :one
|
|
INSERT INTO core.role_assignments (role_id, person_id, org_id, scope_type, scope_id)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING assignment_id, role_id, person_id, org_id, scope_type, scope_id, created_at, updated_at
|
|
`
|
|
|
|
type CreateRoleAssignmentParams struct {
|
|
RoleID string `json:"role_id"`
|
|
PersonID string `json:"person_id"`
|
|
OrgID string `json:"org_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID string `json:"scope_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateRoleAssignment(ctx context.Context, arg CreateRoleAssignmentParams) (RoleAssignment, error) {
|
|
row := q.db.QueryRowContext(ctx, createRoleAssignment,
|
|
arg.RoleID,
|
|
arg.PersonID,
|
|
arg.OrgID,
|
|
arg.ScopeType,
|
|
arg.ScopeID,
|
|
)
|
|
var i RoleAssignment
|
|
err := row.Scan(
|
|
&i.AssignmentID,
|
|
&i.RoleID,
|
|
&i.PersonID,
|
|
&i.OrgID,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getRoleAssignmentsByPersonAndOrg = `-- name: GetRoleAssignmentsByPersonAndOrg :many
|
|
SELECT ra.assignment_id, ra.role_id, ra.person_id, ra.org_id, ra.scope_type, ra.scope_id, ra.created_at, ra.updated_at, r.role_name, r.display_name as role_display_name, r.permissions
|
|
FROM core.role_assignments ra
|
|
JOIN core.roles r ON r.role_id = ra.role_id
|
|
WHERE ra.person_id = $1 AND ra.org_id = $2
|
|
`
|
|
|
|
type GetRoleAssignmentsByPersonAndOrgParams struct {
|
|
PersonID string `json:"person_id"`
|
|
OrgID string `json:"org_id"`
|
|
}
|
|
|
|
type GetRoleAssignmentsByPersonAndOrgRow struct {
|
|
AssignmentID string `json:"assignment_id"`
|
|
RoleID string `json:"role_id"`
|
|
PersonID string `json:"person_id"`
|
|
OrgID string `json:"org_id"`
|
|
ScopeType string `json:"scope_type"`
|
|
ScopeID string `json:"scope_id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
RoleName string `json:"role_name"`
|
|
RoleDisplayName string `json:"role_display_name"`
|
|
Permissions []string `json:"permissions"`
|
|
}
|
|
|
|
func (q *Queries) GetRoleAssignmentsByPersonAndOrg(ctx context.Context, arg GetRoleAssignmentsByPersonAndOrgParams) ([]GetRoleAssignmentsByPersonAndOrgRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getRoleAssignmentsByPersonAndOrg, arg.PersonID, arg.OrgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetRoleAssignmentsByPersonAndOrgRow{}
|
|
for rows.Next() {
|
|
var i GetRoleAssignmentsByPersonAndOrgRow
|
|
if err := rows.Scan(
|
|
&i.AssignmentID,
|
|
&i.RoleID,
|
|
&i.PersonID,
|
|
&i.OrgID,
|
|
&i.ScopeType,
|
|
&i.ScopeID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.RoleName,
|
|
&i.RoleDisplayName,
|
|
pq.Array(&i.Permissions),
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getSystemRoleByName = `-- name: GetSystemRoleByName :one
|
|
SELECT role_id, org_id, role_name, display_name, description, is_system, permissions, created_at, updated_at FROM core.roles
|
|
WHERE role_name = $1 AND is_system = TRUE
|
|
`
|
|
|
|
func (q *Queries) GetSystemRoleByName(ctx context.Context, roleName string) (Role, error) {
|
|
row := q.db.QueryRowContext(ctx, getSystemRoleByName, roleName)
|
|
var i Role
|
|
err := row.Scan(
|
|
&i.RoleID,
|
|
&i.OrgID,
|
|
&i.RoleName,
|
|
&i.DisplayName,
|
|
&i.Description,
|
|
&i.IsSystem,
|
|
pq.Array(&i.Permissions),
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|