shiftpad

package module
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: MIT Imports: 18 Imported by: 0

README

shiftpad

Like Etherpad, but for shift schedules.

Documentation

Index

Constants

View Source
const MaxFuture = 180 * 24 * time.Hour

MaxFuture specifies how far in the future shifts can be created and edited, and the expiry time of pads.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")
View Source
var SystemLocation *time.Location = GetSystemLocation()

Functions

func CheckBeginEnd

func CheckBeginEnd(begin, end time.Time, pastAlways bool, future time.Duration) error

CheckBeginEnd checks that begin or end are non-zero, that end is after begin (or end is zero), and that begin and end are not too far in the past and future.

func GetInterval

func GetInterval(repo Repository, pad *Pad, from, to time.Time, location *time.Location) ([]Event, []Shift, error)

weeks can't be split into days because shifts and events may be contained in multiple days then, but we want them just once in a week (or any other interval)

func GetSystemLocation

func GetSystemLocation() *time.Location

GetSystemLocation returns the location linked by /etc/localtime if it is a canonical location, or "Etc/GMT" else.

func Intersect

func Intersect(as, bs []string) []string

func Locations

func Locations(loc string) []string

Locations returns the list of canonical locations plus the given location, which might be a legacy one.

func Union added in v0.5.0

func Union(as, bs []string) []string

Types

type Auth

type Auth struct {
	Admin            bool
	Apply            []string
	ApplyAll         bool
	Edit             []string
	EditAll          bool
	EditRetroAlways  bool
	Expires          string // yyyy-mm-dd
	Note             string
	PayoutAll        bool
	Take             []string
	TakeAll          bool
	TakeDeadline     string   // apply and take, cronexpr
	TakerName        []string // apply and take
	TakerNameAll     bool     // apply and take
	ViewTakerContact bool
	ViewTakerName    bool // also visible if contained in Auth.TakerName
}

func DecodeAuth

func DecodeAuth(s string) (Auth, error)

func (Auth) Active

func (auth Auth) Active() bool

Active returns true if an expiry date is set and is not in the past.

func (Auth) CanApply added in v0.5.0

func (auth Auth) CanApply(shiftname string) bool

func (Auth) CanApplyName added in v0.5.0

func (auth Auth) CanApplyName(shift Shift, name string) bool

func (Auth) CanApplyShift added in v0.5.0

func (auth Auth) CanApplyShift(shift Shift) bool

func (Auth) CanEdit

func (auth Auth) CanEdit(shiftname string) bool

func (Auth) CanEditAnyShift added in v0.7.0

func (auth Auth) CanEditAnyShift() bool

func (Auth) CanEditShift

func (auth Auth) CanEditShift(shift Shift) bool

When editing a shift, CanEditShift must be called on the original and on the modified shift.

func (Auth) CanPayout added in v0.6.0

func (auth Auth) CanPayout() bool

func (Auth) CanPayoutTake added in v0.6.0

func (auth Auth) CanPayoutTake(shift Shift, take Take) bool

func (Auth) CanTake

func (auth Auth) CanTake(shiftname string) bool

func (Auth) CanTakeShift

func (auth Auth) CanTakeShift(shift Shift) bool

func (Auth) CanTakerName

func (auth Auth) CanTakerName(shift Shift, name string) bool

func (Auth) Encode

func (auth Auth) Encode() ([]byte, error)

Encode copies the contents of auth into url.Values and encodes them. Note that url.Values are designed for url queries, not url path elements. The only difference is the representation of the space character.

func (Auth) Restrict

func (ref Auth) Restrict(input Auth) Auth

Restricts returns a copy of input which is restricted to a reference Auth. Note that this function is not symmetric and thus not an intersection.

type AuthPad

type AuthPad struct {
	Auth
	*Pad
}

An AuthPad is a pad with verified authentication.

func Verify

func Verify(pad *Pad, authstr, sig string) (AuthPad, error)

Verify verifies the given base64-encoded signature of the given auth string, decodes the auth string and checks auth.Active().

func (AuthPad) EditShiftNames

func (ap AuthPad) EditShiftNames() []string

EditShiftNames returns the shift names that may be edited explicitly. You must check EditAll separately.

func (ap AuthPad) Link() string

func (AuthPad) Readonly added in v0.7.3

func (ap AuthPad) Readonly() AuthPad

useful for ical link

type Day

type Day struct {
	Begin  time.Time // inclusive
	End    time.Time // exclusive
	Events []Event
	Shifts []Shift // shifts without an event
}

func GetDay

func GetDay(repo Repository, pad *Pad, date time.Time, location *time.Location) (Day, error)

date must be any time in the day

func (Day) Groups

func (day Day) Groups() []Event

type Event

type Event struct {
	*ical.Event
	Shifts []Shift
}

func (Event) GetUID added in v0.7.1

func (event Event) GetUID() string

type Pad

type Pad struct {
	ID string

	Description string
	ICalOverlay string
	LastUpdated string         // yyyy-mm-dd, update on take and edit (updating on view would cost some performance)
	Location    *time.Location // must not be nil
	Name        string
	PrivateKey  ed25519.PrivateKey
	ShiftNames  []string
}

func NewPad

func NewPad() (Pad, error)

type Repository

type Repository interface {
	GetICalFeedCache(url string) *ical.FeedCache
	GetShifts(pad *Pad, from, to int64) ([]Shift, error) // begin: from inclusive, to exclusive
	GetShiftsByEvent(pad *Pad, eventUID string) ([]Shift, error)
}

type Shift

type Shift struct {
	ID       int
	Modified time.Time // used in ical export
	Name     string    // matched against Pad.ShiftNames
	Note     string
	Paid     bool
	EventUID string
	Quantity int
	Begin    time.Time // required
	End      time.Time // required
	Takes    []Take
}

func (Shift) AfterDeadline

func (shift Shift) AfterDeadline(deadline string) bool

func (Shift) FullyTaken added in v0.4.0

func (shift Shift) FullyTaken() bool

func (Shift) HasPayouts added in v0.6.0

func (shift Shift) HasPayouts() bool

func (Shift) Hours added in v0.6.0

func (shift Shift) Hours() float64

func (Shift) Over

func (shift Shift) Over() bool

func (Shift) String added in v0.5.0

func (shift Shift) String() string

func (Shift) TakeViews added in v0.5.0

func (shift Shift) TakeViews(auth Auth) []Take

TakeViews returns shift.Takes with auth.ViewTakerName and auth.ViewTakerContact applied. Anonymous takes are summarized to "n × anonymous".

func (Shift) Untaken added in v0.4.0

func (shift Shift) Untaken() []struct{}

type Take added in v0.4.0

type Take struct {
	ID       int
	Name     string
	Contact  string
	Approved bool
	PaidOut  bool // not PaymentDue (although the zero value would be a good default) because its meaning would change if shift.Paid is changed, and because keeping track of payments is important
}

func (Take) String added in v0.5.0

func (take Take) String() string

type Week

type Week struct {
	Begin time.Time
	End   time.Time
	Days  [7]*Day
}

func GetWeek

func GetWeek(repo Repository, pad *Pad, year, week int, location *time.Location) (Week, error)

date must be any time in the week

Directories

Path Synopsis
cmd
Package sqlite stores pads and shifts in a SQLite database.
Package sqlite stores pads and shifts in a SQLite database.

Jump to

Keyboard shortcuts

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