UXInteract / task_039 /instruction.md
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
|
Raw History Blame Contribute Delete
1.85 kB
# Filter and audit sensitive-content submissions
Implement the Go `contentsafety` package in the supplied project. Check questions, answers and comments against a configurable sensitive-word list before accepting them.
## Interface
```go
func NewFilter(words []string) *Filter
func LoadWordsFile(path string) ([]string, error)
func NewFilterFromFile(path string) (*Filter, error)
func (f *Filter) SetWords(words []string)
func (f *Filter) Validate(contentType, text string) error
func (f *Filter) Submit(contentType, text string) error
func (f *Filter) AuditLog() []AuditEntry
func (f *Filter) Accepted() []SubmittedEntry
```
Keep the `AuditEntry` fields `ContentType`, `Text` and `Word`; expose `ContentType` and `Text` string fields on `SubmittedEntry`. The starter includes UTF-8 `sensitive_words.txt`, one entry per line. An administrator can edit and reload this file or update the API's word list. An administrator UI is optional; no Apache Answer instance is needed. Local packages are allowed; `go test ./...` must work offline.
## Acceptance Checklist
- Read entries in file order, preserving case, trimming surrounding whitespace and ignoring blank and `#` comment lines. Return an error for a missing or unreadable file.
- For `question`, `answer` and `comment`, detect nonblank configured words as case-insensitive substrings. A match returns an error indicating sensitive content and appends exactly one audit entry with the original text, type and configured word. A clean validation adds no audit entry.
- Clean submissions go to the accepted list; blocked submissions do not. Unsupported types are rejected without changing either list.
- The constructor and `SetWords` take independent snapshots. Updates replace the old list immediately; nil and empty lists clear it. Returned audit and accepted lists are independent snapshots.