feat: auth-roles, image-gallery, click-to-open (#166)

* schema changes

* db generate

* db migration

* add role based middleware

* implement attachment token access

* generate docs

* implement role based auth

* replace attachment specific tokens with gen token

* run linter

* cleanup temporary token implementation
This commit is contained in:
Hayden 2022-12-03 10:55:00 -09:00 committed by GitHub
parent 974d6914a2
commit de419dc37d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 3127 additions and 244 deletions

View file

@ -0,0 +1,81 @@
// Code generated by ent, DO NOT EDIT.
package authroles
import (
"fmt"
)
const (
// Label holds the string label denoting the authroles type in the database.
Label = "auth_roles"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldRole holds the string denoting the role field in the database.
FieldRole = "role"
// EdgeToken holds the string denoting the token edge name in mutations.
EdgeToken = "token"
// Table holds the table name of the authroles in the database.
Table = "auth_roles"
// TokenTable is the table that holds the token relation/edge.
TokenTable = "auth_roles"
// TokenInverseTable is the table name for the AuthTokens entity.
// It exists in this package in order to avoid circular dependency with the "authtokens" package.
TokenInverseTable = "auth_tokens"
// TokenColumn is the table column denoting the token relation/edge.
TokenColumn = "auth_tokens_roles"
)
// Columns holds all SQL columns for authroles fields.
var Columns = []string{
FieldID,
FieldRole,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "auth_roles"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"auth_tokens_roles",
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
for i := range ForeignKeys {
if column == ForeignKeys[i] {
return true
}
}
return false
}
// Role defines the type for the "role" enum field.
type Role string
// RoleUser is the default value of the Role enum.
const DefaultRole = RoleUser
// Role values.
const (
RoleAdmin Role = "admin"
RoleUser Role = "user"
RoleAttachments Role = "attachments"
)
func (r Role) String() string {
return string(r)
}
// RoleValidator is a validator for the "role" field enum values. It is called by the builders before save.
func RoleValidator(r Role) error {
switch r {
case RoleAdmin, RoleUser, RoleAttachments:
return nil
default:
return fmt.Errorf("authroles: invalid enum value for role field: %q", r)
}
}

View file

@ -0,0 +1,176 @@
// Code generated by ent, DO NOT EDIT.
package authroles
import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
})
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
v := make([]any, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.In(s.C(FieldID), v...))
})
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
v := make([]any, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.NotIn(s.C(FieldID), v...))
})
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldID), id))
})
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldID), id))
})
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldID), id))
})
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
})
}
// RoleEQ applies the EQ predicate on the "role" field.
func RoleEQ(v Role) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldRole), v))
})
}
// RoleNEQ applies the NEQ predicate on the "role" field.
func RoleNEQ(v Role) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldRole), v))
})
}
// RoleIn applies the In predicate on the "role" field.
func RoleIn(vs ...Role) predicate.AuthRoles {
v := make([]any, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.In(s.C(FieldRole), v...))
})
}
// RoleNotIn applies the NotIn predicate on the "role" field.
func RoleNotIn(vs ...Role) predicate.AuthRoles {
v := make([]any, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.AuthRoles(func(s *sql.Selector) {
s.Where(sql.NotIn(s.C(FieldRole), v...))
})
}
// HasToken applies the HasEdge predicate on the "token" edge.
func HasToken() predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TokenTable, FieldID),
sqlgraph.Edge(sqlgraph.O2O, true, TokenTable, TokenColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasTokenWith applies the HasEdge predicate on the "token" edge with a given conditions (other predicates).
func HasTokenWith(preds ...predicate.AuthTokens) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(TokenInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2O, true, TokenTable, TokenColumn),
)
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.AuthRoles) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
})
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.AuthRoles) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
}
s.Where(s1.P())
})
}
// Not applies the not operator on the given predicate.
func Not(p predicate.AuthRoles) predicate.AuthRoles {
return predicate.AuthRoles(func(s *sql.Selector) {
p(s.Not())
})
}