SUMMARY
Browsers send empty strings for empty fields in form submissions.
Email is optional in registration process but empty field fails
validation for email and results in 400 bad request. Converting
empty strings to None fixes this.
SUMMARY
crate::errors::ServiceError is for JSON APIs.
crate::page::errors::PageError is implemented for HTML pages. It
takes a template and ServiceError instance to render given template
with error message.
If a user submits a form, which errors out, the user should be
presented the same form, values filled but with error message
included.
DESCRIPTION
PageError::reason is human readable and friendly message
explain what had happened.
PageError::title is the name of the status code: HTTP "200: is "200
OK"
crate::page::errors::CtxError: trait all templates that can error
should implement. It accepts an error and appends it to the
templates context before rendering it.
SUMMARY
New field is added to settings to receive email of the admin of the
instance. source_code is a link to the repository of the source code
of a GitPad instance, set_source_code is defined to build a HTTP
link to the exact commit from which the instance binary was built.
NOTE
Current Settings::set_source_code assumes the provided HTTP link to
point to a forge belonging to the GitHub-family(GitHub, Gitea and
GitLab), provisions must be made to accommodate other forges as
well.
DESCRIPTION
Each comment is uniquely identified by database assigned, serially
incremented ID. Access controlled REST endpoint is added to delete
comment by ID.
ERRORS RETURNED
- Gist doesn't exist: 404 GistNotFound
- Gist is private and requesting user is not owner or is not visible
to user: 404 GistNotFound
- Gist exists and is visible to requesting user but comment doesn't
exist: 404 CommentNotFound
- Gist exists and is visible to requesting user is not comment owner
: 401 UnauthorizedOperation
DESCRIPTION
Get all comments on a gist. Access controlled but optionally
authenticated HTTP REST endpoint is added to get comment by ID.
ERRORS RETURNED
- Gist doesn't exist: 404 GistNotFound
- Gist is private and requesting user is not owner or is not
authenticated: 404 GistNotFound
DESCRIPTION
Each comment is uniquely identified by database assigned, serially
incremented ID. Access controlled but optionally authenticated HTTP
REST endpoint is added to get comment by ID.
ERRORS RETURNED
- Gist doesn't exist: 404 GistNotFound
- Gist is private and requesting user is not ower or is not
authenticated: 404 GistNotFound
- Comment is empty: 400 EmptyComment
- Gist exists and is visible to requesting user but comment doesn't
exist: 404 CommentNotFound
SUMMARY
Comment on gist and utilities to generate post comment REST
endpoint route from username and gist public ID component
ERRORS
- Gist doesn't exist, 404 GistNotFound is returned
- Gist is private and commenting user is not ower, 404 GistNotFound
is returned
- Comment is empty, 400 EmptyComment is returned
SUMMARY
Optionally authenticated endpoint to read file in gist repository.
Subject to gist visibility.
DESCRIPTION
crate::api::v1::gists::read_file
- Parses URI for gist owner, gist public ID and file path.
- Contents of gists with private visibility are only returned
to owner of gists. Identity determined using session cookies.
- Contents are Unlisted and Public visibility gists are
accessible by both unauthenticated and authenticated
users(authenticated but not owner).
SUMMARY
This program supports directories in gists. This patch modifies
Data::read_file to support directory reads. Additionally,
CreateGistRequest is modified to accept files in subdirectories.
DESCRIPTION
Data::read_file
When repository contains subdirectories, it will recursively
read all files and return their contents.
crate::data::api::v1::gists::GitFileMode
Set of known(to me) file modes that Git uses.
GitFileMode::Unsupported is used to take advantage of
num_enum::FromPrimitive. The alternative would have been
num_enum::TryFromPrimitive, which returns errors on unsupported
values. I felt the former was cleaner.
SUMMARY
Binary content is essential to store images. ContentType enum
accommodates both utf-8 and and non utf-8 encodings.
Data::write_file and Data::read_file are modified to handle
ContentType enum
SUMMARY
GistDatabase::get_user_gists retrieved all gists that were created by
the user. GistDatabase::get_user_public_gists and
GistDatabase::get_user_public_unlisted_gists produce
visibility-filtered results
DESCRIPTION
Gist visibility levels are ordered in the following order:
---------------------------------
| Public < Unlisted < Private |
---------------------------------
A user with permissions to access a visibility-level will
also have access to the levels lower levels to it. Accessibility
filters use this mechanism to filter gists: a higher
visibility-level request will also return gists with lower
visibility-levels.
GistDatabase::get_user_public_unlisted_gists:
Return all gists that belong to a user with
public(GistVisibility::Public) and
unlisted(GistVisibility::UnliUnlisted) visibility levels. Gists
with private(GistVisibility::Private) visibility levels are
ignored.
GistDatabase::get_user_public_gists:
Return all gists that belong to a user with
public(GistVisibility::Public) only is returned. Private and
Unlisted resources are ignored.
GistDatabase::get_user_gists:
Returns all gists belonging to a user
SUMMARY
Data::write_file
Creates a new files and commits them to "master" branch on the
bare repository allocated for the gist. If multiple files are
supplied, all files are written and committed in a single
commit.
Currently, empty commit message is used but this should probably
be changed.
If filename includes spaces it is escaped. Example "foo bar".txt
is escaped and converted into "foo\ bar".txt.
Data::read_file
Reads files already committed to the repository allocated for
the gist. This method expects filenames provided to be already
escaped. Failure would result in file not found errors
Data::get_repository_path
Receives gist public ID and returns path of the repository
allocated for the gist. Programmers are expected to use this
method to work on the repositories instead of manually
constructing paths.
crate::utils::escape_spaces
Escapes spaces in the provided string, "foo bar".txt is
converted to "foo\ bar".txt
DESCRIPTION
Data::new_gist creates a bare repository in the supplied
Data.settings.repository.root directory and saves metadata in the
database
See accompanying test for usage