113 Commits (4127f923aa174ecebed93898dd39c1b21b6b2605)
 

Author SHA1 Message Date
Aravinth Manivannan 2a8df0ebb8
feat: register template renders errors 2 years ago
Aravinth Manivannan 5c9a96dfab
feat: add tests for login template 2 years ago
Aravinth Manivannan 2919611e00
feat: login template renders errors 2 years ago
Aravinth Manivannan 3d684ff53f
feat: error component 2 years ago
Aravinth Manivannan 8901191549
feat: empty homepage placeholder 2 years ago
Aravinth Manivannan f03c052471
feat: implement HTML PageError
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.
2 years ago
Aravinth Manivannan 9fdd467fe9
feat: implement GetLoginRoute for crate::pages::route::Pages 2 years ago
Aravinth Manivannan 037b7f1b97
feat: HTTP signout route 2 years ago
Aravinth Manivannan 58fbe892b3
chore: separate API logout route 2 years ago
Aravinth Manivannan 34e8d8851f
feat: login and register HTML pages 2 years ago
Aravinth Manivannan 2cf064d565
feat: setup embedding static files in binary 2 years ago
Aravinth Manivannan 9dd7f2e1c7
chore: rm errors.rs from coverage report and cleanup protected_routes_work 2 years ago
Aravinth Manivannan 6d2b071308
feat: add basic styling 2 years ago
Aravinth Manivannan 9249dc3567
feat: setup cache busting for static assets 2 years ago
Aravinth Manivannan fc40706ca9
feat: get admin_email in settings and validate admin_email and source_code
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.
2 years ago
Aravinth Manivannan b7fe7ea5d5
chore: rename gists to gitpad 2 years ago
Aravinth Manivannan 604d887164
feat: REST endpoint to delete comment by ID
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
2 years ago
Aravinth Manivannan 3af7c7c0f8
feat: add delete request test util 2 years ago
Aravinth Manivannan b85ef1d531
chore: use constants to convert ServiceError to StatusCode 2 years ago
Aravinth Manivannan 043211a357
feat: REST endpoint to get all comments on a gist
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
2 years ago
Aravinth Manivannan f8b9172b88
feat: REST endpoint to get comment by ID
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
2 years ago
Aravinth Manivannan 7fce5302e1
feat: get_comment route and tests for all path builder methods on Gist 2 years ago
Aravinth Manivannan c58a6f1fae
feat: REST endpont return comment ID after creation 2 years ago
Aravinth Manivannan c252f06b16
feat: return comment ID after comment creation 2 years ago
Aravinth Manivannan ae08828ac4
chore: add license header 2 years ago
Aravinth Manivannan 96be68c734
fix and chore: apply clippy lints and create_gist returns gist public ID
fixes #1
2 years ago
Aravinth Manivannan 4a8b72c7d5
chore: use crata::db::* to init DB connection in tests 2 years ago
Aravinth Manivannan 3fca4a4f99
feat: update todo list 2 years ago
Aravinth Manivannan b58a2fcee0
feat: REST endpoint to post comment on gist
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
2 years ago
Aravinth Manivannan 91be25d9f6
fix: serve get_file under contents/ 2 years ago
Aravinth Manivannan a8718dc73e
feat: REST endpoint to read file in gist repository
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).
2 years ago
Aravinth Manivannan 3b4d944291
feat: Gist::get_file_route utility method to substitute values in get file routes 2 years ago
Aravinth Manivannan bcb3545f8f
feat: utils: ErrorToResponse implements Debug and get_request accepts cookies 2 years ago
Aravinth Manivannan 632fe272fa
feat: read_file processes directories
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.
2 years ago
Aravinth Manivannan 311964f32f
feat: add gitea oauth integration to feat list 2 years ago
Aravinth Manivannan 197950c3b2
feat: accommodate binary file content
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
2 years ago
Aravinth Manivannan 06830bfd2c
feat: DB: visibility filtered gist retrieval
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
2 years ago
Aravinth Manivannan 7cdfcc47bb
feat: HTTP JSON endpoint to create new gist 2 years ago
Aravinth Manivannan 82acb06eac
feat: Data::write_file accepts gist ID/gist repository & test cleanup 2 years ago
Aravinth Manivannan 44d920f6ea
feat: implement serialization and deserialiation for Gist, GIstPrivacy and GistComments in db_core 2 years ago
Aravinth Manivannan 18865552e1
feat: Data::write_file and Data::read_file to save and read gists
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
2 years ago
Aravinth Manivannan 303a4ab0ba
feat: helper method Data::new_gist to create new gist and tests
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
2 years ago
Aravinth Manivannan c636826ecf
fix: cargo fmt 2 years ago
Aravinth Manivannan 79704087f6
fix: change function parameters into references 2 years ago
Aravinth Manivannan 303a430113
fix: rename GistPrivacy to GistVisibility and *privacy to *visibility 2 years ago
Aravinth Manivannan 6b60e2a064
feat: add gists_gists, gists_comments and gists_comments & related methods
The following changes are implemented for both db-sqlx-postgres and
db-sqlx-sqlite:

TABLE gists_gists
    Stores gist metadata with unique index on gists_gists.public_id for fast
    lookups

TABLE gists_comments
    Stores comment metadata

TABLE gists_privacy
    Stores gist privacy: sqlx currently doesn't have support Postgres
    enums(ref: https://github.com/launchbadge/sqlx/issues/1171), so storing
    possible privacy values as references from this table.

    This table shouldn't be mutated during runtime. Possible values are
    already recorded in database during migrations. All runtime operations
    on this table must only take references.

    Each implementation of GistDatabase also includes a method called
    privacy_exists, which is called during tests to ensure that
    migrations are successful.

VIEW gists_gists_view
    Gist lookups combines data from gists_users, gists_gists and
    gists_privacy. This SQL view boots performance(I think?). At any rate,
    it is much nicer to work with.

QUIRKS
    Database indexes are i64 in SQLite while i32 in Postgres
2 years ago
Aravinth Manivannan e96550b6c0
feat: db-sqlx-postgres: reaname admin_users -> gists_users 2 years ago
Aravinth Manivannan 9bf3dad060
feat: db-sqlx-sqlite: reaname admin_users -> gists_users 2 years ago
Aravinth Manivannan 9c35c6f99b
feat: add tests for health meta route 2 years ago
Aravinth Manivannan 6fc667ffc9 feat: run migrations on start up 2 years ago