Documentation
¶
Overview ¶
Package assignment covers reading assignments and handing work in.
Submitting is the reason this project exists. Moodle's own model has two steps that look like one: saving content, and handing it in for grading. A client that calls only the first and reports success leaves the student believing work was submitted when it is still a draft. Every path here ends by reading the state back from Moodle and reporting what Moodle says.
Index ¶
- Constants
- type Attempt
- type Backend
- type Content
- type Detail
- type ListResult
- type OnlineText
- type OnlineTextContent
- type Outcome
- type OverviewItem
- type OverviewResult
- type Service
- func (s *Service) List(ctx context.Context, capabilities *site.Capabilities, courseIDs []string) (ListResult, error)
- func (s *Service) Locate(ctx context.Context, capabilities *site.Capabilities, ref string) (string, error)
- func (s *Service) Overview(ctx context.Context, capabilities *site.Capabilities, courseIDs []string) (OverviewResult, error)
- func (s *Service) Show(ctx context.Context, capabilities *site.Capabilities, assignmentID string) (Detail, error)
- func (s *Service) Status(ctx context.Context, capabilities *site.Capabilities, assignmentID string) (State, error)
- func (s *Service) Submit(ctx context.Context, capabilities *site.Capabilities, req SubmitRequest) (SubmitResult, error)
- type State
- type Status
- type Step
- type StepName
- type StepStatus
- type SubmitRequest
- type SubmitResult
- type Submitter
- type Summary
- type Writer
Constants ¶
const ( PluginFile = "file" PluginOnlineText = "onlinetext" )
Plugin names this tool knows how to submit for.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attempt ¶
type Attempt struct {
// Number is Moodle's own attempt number, counting from zero.
Number int
Status Status
FileCount int
SavedAt *time.Time
}
Attempt is one earlier submission, kept apart from the current one because it is finished: nothing about it can change, and its status is a record of what happened rather than a description of what to do next.
type Backend ¶
type Backend interface {
Name() site.BackendKind
Requirement() site.Requirement
List(ctx context.Context, courseIDs []string) (ListResult, error)
Show(ctx context.Context, assignmentID string) (Detail, error)
Status(ctx context.Context, assignmentID string) (State, error)
}
Backend reads assignments and their state.
type Content ¶
type Content struct {
// FileDraftID is the draft area holding the uploaded files.
FileDraftID string
// OnlineText is set only when the assignment enables that plugin.
OnlineText *OnlineTextContent
}
Content is everything one save_submission call carries.
Moodle saves every enabled plugin in a single call, so this has to describe all of them at once. Sending only the part that changed would save the rest as empty.
type Detail ¶
type Detail struct {
Summary
// Description is Moodle's own text, unchanged. It is usually HTML, which
// DescriptionFormat identifies; rewriting it here would be guessing at how
// the caller wants to render it.
Description string
DescriptionFormat int
// MaxGrade is the number the work is marked out of. Zero means the
// assignment is not graded.
MaxGrade float64
// AllowFrom is when submissions open, nil when they are open already.
AllowFrom *time.Time
// TimeLimit is in seconds; zero means no limit.
TimeLimit int
// MaxAttempts is -1 when Moodle allows unlimited attempts.
MaxAttempts int
TeamSubmission bool
BlindMarking bool
// IdentitiesRevealed reports that anonymity has been lifted. While it is
// false and BlindMarking is true, Moodle can withhold a grade it already
// holds, so an empty grade is not evidence that nothing was marked.
IdentitiesRevealed bool
// Attachments are the files the teacher attached to the description.
Attachments []file.Ref
// Provenance says which fields the route could not read. It may be left
// zero by a route that reads everything; the submission state beside it
// carries the source.
Provenance site.Provenance
}
Detail is everything an assignment says about itself.
It is separate from Summary because a listing does not want the description of every assignment, and a single assignment's view is useless without it.
type ListResult ¶
type ListResult struct {
Assignments []Summary
Provenance site.Provenance
}
ListResult is a set of assignments plus where it came from.
type OnlineText ¶
type OnlineText struct {
Text string
// Format is Moodle's text format id, passed through rather than
// interpreted: rewriting it would change how the text renders.
Format int
}
OnlineText is the content of an online text submission.
type OnlineTextContent ¶
type OnlineTextContent struct {
Text string
Format int
// DraftID must be a draft area of its own. Reusing the file area's id
// makes Moodle move the uploaded files into the text plugin's storage,
// after which the file plugin finds nothing and the save is rejected.
DraftID string
}
OnlineTextContent is the online text half of a submission.
type Outcome ¶
type Outcome string
Outcome says what happened overall.
const ( // OutcomeApplied means the work reached the state the caller asked for, // confirmed by reading it back. OutcomeApplied Outcome = "applied" // OutcomeNotApplied means nothing changed. OutcomeNotApplied Outcome = "not_applied" // OutcomePlanned is the result of a dry run. OutcomePlanned Outcome = "planned" )
type OverviewItem ¶ added in v0.4.0
type OverviewItem struct {
Assignment Summary
Submission *State
StatusErrorCode errs.Code
StatusErrorReason errs.Reason
}
OverviewItem keeps a failed status read distinct from an unsubmitted item. A list may be readable even when Moodle refuses the status of one activity.
type OverviewResult ¶ added in v0.4.0
type OverviewResult struct {
Items []OverviewItem
Provenance site.Provenance
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the assignment use case.
There is one backend today. It still owns the choice rather than the command layer, because the AJAX and HTML routes arrive later and the decision of which to use belongs to the feature, not to the presentation.
func NewService ¶
NewService builds the use case. The first backend is the one trusted to submit; the rest are read-only alternatives.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, capabilities *site.Capabilities, courseIDs []string) (ListResult, error)
List returns the assignments of the given courses, or of every course the account is enrolled in when none are named.
func (*Service) Locate ¶
func (s *Service) Locate(ctx context.Context, capabilities *site.Capabilities, ref string) (string, error)
Locate turns what the caller typed into an assignment id.
A bare number is already one. Anything else is read as a Moodle address, which is what someone has in their clipboard after looking at the assignment in a browser. Those addresses carry the course module id rather than the assignment's own id, so getting from one to the other takes a lookup — the two are both small integers and are not interchangeable.
func (*Service) Overview ¶ added in v0.4.0
func (s *Service) Overview(ctx context.Context, capabilities *site.Capabilities, courseIDs []string) (OverviewResult, error)
Overview lists assignments once, then reads each account-specific state. A small fixed worker pool bounds the number of simultaneous page requests; the wire still requires one status read per assignment on Moodle sites that do not expose a bulk submission-status function.
func (*Service) Show ¶
func (s *Service) Show(ctx context.Context, capabilities *site.Capabilities, assignmentID string) (Detail, error)
Show returns one assignment's full definition.
func (*Service) Status ¶
func (s *Service) Status(ctx context.Context, capabilities *site.Capabilities, assignmentID string) (State, error)
Status reports where one submission stands.
func (*Service) Submit ¶
func (s *Service) Submit(ctx context.Context, capabilities *site.Capabilities, req SubmitRequest) (SubmitResult, error)
Submit hands work in.
type State ¶
type State struct {
Status Status
// CanEdit and CanSubmit are Moodle's own verdicts. CanEdit accounts for
// cut-off dates, group membership and permissions, which a client cannot
// infer. CanSubmit is narrower than its name suggests: Moodle sets it when
// there is saved work waiting to be handed in, so it is false on an
// assignment nothing has been saved to yet. It is not permission to
// submit, and nothing here gates on it.
CanEdit bool
CanSubmit bool
// ExtensionDue is when this account in particular may submit until, nil
// when no extension was granted. It is per person, so it cannot be read
// off the assignment: the cut-off printed there can be in the past while
// this one is still ahead, and Moodle will accept the work.
ExtensionDue *time.Time
// GroupSubmission reports that this is a group's submission rather than
// this account's own. "Handed in: yes" then means the group's work is in,
// which is not the same sentence.
GroupSubmission bool
// MembersStillToSubmit counts the group members Moodle says have yet to
// submit, nil when the reply did not carry the list at all.
//
// Zero still covers two situations even when the list did arrive: nobody
// is left, and the assignment does not require every member to submit —
// Moodle fills the list only in the second case. So zero is not evidence
// that a group has finished, and only a count above zero says anything.
MembersStillToSubmit *int
// OnlineSubmission reports whether Moodle has any submission plugin
// switched on. False is an offline assignment — marked from work done
// somewhere else — which is a normal, deliberate setting and not a fault:
// it can carry a grade and feedback like any other.
//
// It is a pointer because a route that cannot see the setting must not
// answer it. Reading the zero value would call every assignment offline
// on the page-reading route, which has no way to know.
OnlineSubmission *bool
// TimerEndsAt is when a started time limit runs out, nil when the
// assignment has no limit or this account has not started it.
//
// It is not a deadline. Moodle accepts work after the timer expires and
// marks it as over time; what actually closes submission is the cut-off.
// Calling this the deadline would be a confident wrong answer in the other
// direction from ignoring it.
TimerEndsAt *time.Time
// Earlier is what this account handed in before a grader reopened the
// assignment, oldest first. It is empty on an assignment that was never
// reopened, and the site sends it to the student themselves rather than
// only to a grader — so a reopened submission need not look like a first
// one that was never handed in.
Earlier []Attempt
// GradingStatus is Moodle's word for whether it has been marked.
GradingStatus string
ModifiedAt *time.Time
FileCount int
// OnlineText is what the student has already typed, when the assignment
// takes online text. It is read so that submitting files can put it back
// unchanged instead of blanking it.
OnlineText *OnlineText
// Files are what has actually been handed in, so a caller can check that
// what Moodle holds is what they meant to send.
Files []file.Ref
// Provenance tells the caller which backend answered.
Provenance site.Provenance
}
State is the caller's current submission for an assignment.
type Status ¶
type Status string
Status is where a submission stands.
const ( // StatusNew means nothing has been saved yet. StatusNew Status = "new" // StatusDraft means content is saved but not handed in. Work in this // state is not being marked. StatusDraft Status = "draft" // StatusReopened means a grader reopened the assignment for another // attempt. It is not a draft: the earlier attempt was handed in, and is // usually already marked. Saying "draft" would report the work as never // submitted to someone whose first attempt was. StatusReopened Status = "reopened" // StatusSubmitted means the work has been handed in for grading. StatusSubmitted Status = "submitted" // StatusUnknown means Moodle reported something this build does not // recognise. It is deliberately not folded into one of the others. StatusUnknown Status = "unknown" )
type Step ¶
type Step struct {
Name StepName
Status StepStatus
Detail string
}
Step is one stage and its outcome.
type StepStatus ¶
type StepStatus string
StepStatus is what happened to a step.
const ( StepDone StepStatus = "done" StepSkipped StepStatus = "skipped" StepPlanned StepStatus = "planned" StepFailed StepStatus = "failed" )
type SubmitRequest ¶
type SubmitRequest struct {
AssignmentID string
Files []string
// AcceptStatement records that the student agreed to the submission
// statement. It is never inferred: agreeing on their behalf would be
// signing something for them.
AcceptStatement bool
// DraftOnly saves the work without handing it in.
DraftOnly bool
DryRun bool
}
SubmitRequest is what the caller wants done.
type SubmitResult ¶
type SubmitResult struct {
Outcome Outcome
// FinalStatus is the state Moodle reports after the fact, not the state
// this code believes it produced.
FinalStatus Status
// HandedIn distinguishes work that is being marked from work that is
// merely saved. This is the distinction other clients lose.
HandedIn bool
Steps []Step
Assignment Summary
Provenance site.Provenance
}
SubmitResult is what happened, as read back from Moodle.
type Submitter ¶
type Submitter struct {
// contains filtered or unexported fields
}
Submitter hands work in.
func NewSubmitter ¶
NewSubmitter builds a Submitter.
func (*Submitter) Submit ¶
func (s *Submitter) Submit(ctx context.Context, req SubmitRequest) (SubmitResult, error)
Submit hands work in and reports what Moodle says afterwards.
The shape of the flow is forced by Moodle's model: saving content and handing it in are separate, and which one is enough depends on the assignment's settings. Reporting success after the first step alone is the mistake this method exists to avoid.
type Summary ¶
type Summary struct {
ID string
CourseID string
// CourseShortName is what distinguishes one row from another when a
// listing spans years: eight instances of a course share a full name and
// an activity name, and only the short name carries the year.
//
// Nil means the route that answered did not say. Reading a course page
// does not carry it, and an empty string there would read as a course
// without a short name, which Moodle does not allow.
CourseShortName *string
CMID string
Name string
DueDate *time.Time
CutOff *time.Time
// SubmissionDrafts reports whether Moodle keeps a separate draft state.
// When it does, saving content is not handing it in, and a second call is
// required.
//
// Nil means the route that answered could not see the setting — reading a
// page cannot. It is kept distinct from false because the difference is
// whether saved work is already submitted, and guessing either way would
// tell a student something untrue about coursework.
SubmissionDrafts *bool
// RequiresStatement reports whether the student must accept a submission
// statement. Agreeing on the student's behalf would be signing something
// for them, so the caller has to pass their consent explicitly.
RequiresStatement bool
MaxFiles int
MaxBytes int64
// Plugins are the submission plugins the assignment has switched on, such
// as "file" and "onlinetext". Saving a submission has to carry data for
// every one of them: Moodle saves them all in one call, and a plugin left
// out is not left alone but saved empty.
Plugins []string
}
Summary is one assignment.
func (Summary) NeedsHandIn ¶
NeedsHandIn reports whether saving content leaves the work as a draft, and whether that is known at all.
type Writer ¶
type Writer interface {
// UploadDraft puts local files in the user's draft area and returns the
// item id that identifies it.
UploadDraft(ctx context.Context, paths []string) (itemID string, err error)
// NewDraftArea allocates an empty draft area. Allocating one is itself a
// write, which is why it is a step of its own rather than a detail hidden
// inside saving.
NewDraftArea(ctx context.Context) (itemID string, err error)
// SaveSubmission writes the submission's content.
SaveSubmission(ctx context.Context, assignmentID string, content Content) error
// SubmitForGrading hands the work in. acceptStatement records that the
// student agreed to the submission statement.
SubmitForGrading(ctx context.Context, assignmentID string, acceptStatement bool) error
}
Writer performs the steps of handing work in.
The steps are separate because their failure modes differ: an upload can be repeated harmlessly, saving cannot, and handing in is the step the student actually cares about.