Commit Graph

75 Commits (56ff863042cb8d6d12f186744942db548891ec1a)

Author SHA1 Message Date
Aravinth Manivannan 56ff863042
feat: add tests for HTML signout route 2022-02-23 19:40:05 +05:30
Aravinth Manivannan 371e56ab47
fix: set authentication session cookie and load middleware 2022-02-23 19:39:06 +05:30
Aravinth Manivannan 28b501810e
feat: separate navigation bars for logged and unauthenticated users
SUMMARY
    Authenticated and unauthenticated users have different requirements.
    Links to profile and settings are irrelevant for unauthenticated
    users. So separate navigation bars.

USAGE
    crate::pages::auth_ctx
	Authenticated user context should be supplied on every
	authenticated route template render. Authenticated navigation
	bar depends on "loggedin_user" to render profile link.

    AUTH_NAV("auth_nav")
	Should only be used in authenticated routes. Depends on
	"loggedin_user" authenticated user context, which can't be
	supplied in unauthenticated routes.

NOTES
    Currently, there's (template)code
    duplication, when inheritance for "include" templates are
    implemented in Tera crate, navigation bars implementations should be
    refactored to avoid duplication.
2022-02-23 12:17:48 +05:30
Aravinth Manivannan 3d040ede86
feat: gist routes and methods to generate profile route from component 2022-02-23 12:07:41 +05:30
Aravinth Manivannan 1f4053f361
feat: load embedded templates 2022-02-23 09:55:06 +05:30
Aravinth Manivannan 551a48d0c5
feat: embed templates in binary 2022-02-23 09:54:22 +05:30
Aravinth Manivannan d0dbfd9729
chore: reorganize templates 2022-02-23 09:52:56 +05:30
Aravinth Manivannan 8dd20a4f52
feat: register templates fills form on err 2022-02-23 08:10:43 +05:30
Aravinth Manivannan 78d24af48c
feat: convert empty emails to None in register form handler
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.
2022-02-23 08:08:02 +05:30
Aravinth Manivannan fdbd62a0a6
feat: add error styling 2022-02-23 08:07:37 +05:30
Aravinth Manivannan 3b6a5938d7
feat: login form submission 2022-02-22 22:03:03 +05:30
Aravinth Manivannan dba0834eff
feat: register form submission 2022-02-22 21:57:13 +05:30
Aravinth Manivannan 2a8df0ebb8
feat: register template renders errors 2022-02-22 21:44:57 +05:30
Aravinth Manivannan 5c9a96dfab
feat: add tests for login template 2022-02-22 21:44:23 +05:30
Aravinth Manivannan 2919611e00
feat: login template renders errors 2022-02-22 10:12:05 +05:30
Aravinth Manivannan 3d684ff53f
feat: error component 2022-02-22 10:09:53 +05:30
Aravinth Manivannan 8901191549
feat: empty homepage placeholder 2022-02-22 10:07:52 +05:30
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.
2022-02-22 10:05:03 +05:30
Aravinth Manivannan 9fdd467fe9
feat: implement GetLoginRoute for crate::pages::route::Pages 2022-02-21 23:42:13 +05:30
Aravinth Manivannan 037b7f1b97
feat: HTTP signout route 2022-02-21 23:41:56 +05:30
Aravinth Manivannan 58fbe892b3
chore: separate API logout route 2022-02-21 23:38:02 +05:30
Aravinth Manivannan 34e8d8851f
feat: login and register HTML pages 2022-02-21 02:22:01 +05:30
Aravinth Manivannan 2cf064d565
feat: setup embedding static files in binary 2022-02-21 02:19:56 +05:30
Aravinth Manivannan 9dd7f2e1c7
chore: rm errors.rs from coverage report and cleanup protected_routes_work 2022-02-21 02:18:44 +05:30
Aravinth Manivannan 6d2b071308
feat: add basic styling 2022-02-21 02:16:00 +05:30
Aravinth Manivannan 9249dc3567
feat: setup cache busting for static assets 2022-02-21 02:15:38 +05:30
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.
2022-02-21 00:42:53 +05:30
Aravinth Manivannan b7fe7ea5d5
chore: rename gists to gitpad 2022-02-20 19:21:28 +05:30
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
2022-02-20 01:04:13 +05:30
Aravinth Manivannan 3af7c7c0f8
feat: add delete request test util 2022-02-20 01:04:01 +05:30
Aravinth Manivannan b85ef1d531
chore: use constants to convert ServiceError to StatusCode 2022-02-20 01:03:25 +05:30
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
2022-02-19 23:52:38 +05:30
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
2022-02-19 23:01:29 +05:30
Aravinth Manivannan 7fce5302e1
feat: get_comment route and tests for all path builder methods on Gist 2022-02-19 21:52:27 +05:30
Aravinth Manivannan c58a6f1fae
feat: REST endpont return comment ID after creation 2022-02-19 21:41:30 +05:30
Aravinth Manivannan c252f06b16
feat: return comment ID after comment creation 2022-02-19 21:40:58 +05:30
Aravinth Manivannan ae08828ac4
chore: add license header 2022-02-19 13:36:21 +05:30
Aravinth Manivannan 96be68c734
fix and chore: apply clippy lints and create_gist returns gist public ID
fixes #1
2022-02-19 13:35:03 +05:30
Aravinth Manivannan 4a8b72c7d5
chore: use crata::db::* to init DB connection in tests 2022-02-19 13:15:08 +05:30
Aravinth Manivannan 3fca4a4f99
feat: update todo list 2022-02-18 23:59:37 +05:30
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
2022-02-18 23:52:21 +05:30
Aravinth Manivannan 91be25d9f6
fix: serve get_file under contents/ 2022-02-18 23:12:52 +05:30
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).
2022-02-18 22:55:01 +05:30
Aravinth Manivannan 3b4d944291
feat: Gist::get_file_route utility method to substitute values in get file routes 2022-02-18 22:54:22 +05:30
Aravinth Manivannan bcb3545f8f
feat: utils: ErrorToResponse implements Debug and get_request accepts cookies 2022-02-18 22:53:28 +05:30
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.
2022-02-18 21:38:38 +05:30
Aravinth Manivannan 311964f32f
feat: add gitea oauth integration to feat list 2022-02-18 12:45:43 +05:30
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
2022-02-16 20:23:04 +05:30
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
2022-02-16 17:13:12 +05:30
Aravinth Manivannan 7cdfcc47bb
feat: HTTP JSON endpoint to create new gist 2022-02-15 23:48:05 +05:30