Commit Graph

49 Commits (fc40706ca992f2b74df26dc415a4e71f52ec74b2)

Author SHA1 Message Date
Aravinth Manivannan fc40706ca9
feat: get admin_email in settings and validate admin_email and source_code
    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.

    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
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
    Each comment is uniquely identified by database assigned, serially
    incremented ID. Access controlled REST endpoint is added to delete
    comment by ID.

    - 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
    Get all comments on a gist. Access controlled but optionally
    authenticated HTTP REST endpoint is added to get comment by ID.

    - 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
    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.

    - 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
    Comment on gist and  utilities to generate post comment REST
    endpoint route from username and gist public ID component

    - 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
    Optionally authenticated endpoint to read file in gist repository.
    Subject to gist visibility.

	- 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
    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.

	When repository contains subdirectories, it will recursively
	read all files and return their contents.

	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
    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
    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

    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

	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

	Return all gists that belong to a user with
	public(GistVisibility::Public) only is returned. Private and
	Unlisted resources are ignored.

	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
Aravinth Manivannan 82acb06eac
feat: Data::write_file accepts gist ID/gist repository & test cleanup 2022-02-15 23:46:31 +05:30
Aravinth Manivannan 44d920f6ea
feat: implement serialization and deserialiation for Gist, GIstPrivacy and GistComments in db_core 2022-02-15 23:46:05 +05:30
Aravinth Manivannan 18865552e1
feat: Data::write_file and Data::read_file to save and read gists
	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

	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.

	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

	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.

	Escapes spaces in the provided string, "foo bar".txt is
	converted to "foo\ bar".txt
2022-02-15 21:29:55 +05:30
Aravinth Manivannan 303a4ab0ba
feat: helper method Data::new_gist to create new gist and tests
    Data::new_gist creates a bare repository in the supplied
    Data.settings.repository.root directory and saves metadata in the

    See accompanying test for usage
2022-02-14 22:46:17 +05:30
Aravinth Manivannan c636826ecf
fix: cargo fmt 2022-02-14 22:42:02 +05:30
Aravinth Manivannan 79704087f6
fix: change function parameters into references 2022-02-14 22:41:07 +05:30
Aravinth Manivannan 303a430113
fix: rename GistPrivacy to GistVisibility and *privacy to *visibility 2022-02-14 20:38:19 +05:30
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

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

TABLE gists_comments
    Stores comment metadata

TABLE gists_privacy
    Stores gist privacy: sqlx currently doesn't have support Postgres
    enums(ref:, 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.

    Database indexes are i64 in SQLite while i32 in Postgres
2022-02-14 20:11:26 +05:30
Aravinth Manivannan e96550b6c0
feat: db-sqlx-postgres: reaname admin_users -> gists_users 2022-02-13 16:50:51 +05:30
Aravinth Manivannan 9bf3dad060
feat: db-sqlx-sqlite: reaname admin_users -> gists_users 2022-02-13 16:49:38 +05:30
Aravinth Manivannan 9c35c6f99b
feat: add tests for health meta route 2022-02-13 16:27:42 +05:30
Aravinth Manivannan 6fc667ffc9 feat: run migrations on start up 2022-02-13 00:18:49 +05:30
Aravinth Manivannan 915fb46445 fix: lints and run migrations before generating coverage in CI 2022-02-13 00:07:28 +05:30
Aravinth Manivannan 34a67a5535 feat: bootstarp gists

- Sign Up
- Sign IN

- Username Exists
- Email Exists
- Account delete
- Password update
- Email update
- Username update
- Get account secret
- Update secret

All routes are implemented with proper error handling and testing

See ./config/default.toml for full list
2022-02-12 23:48:35 +05:30
Aravinth Manivannan 3447a3a45c feat: add git SSH and HTTP clone feature target in README 2022-02-12 23:48:21 +05:30
Aravinth Manivannan f67a0038cf feat : GistDatabase is Clone and add ping to GistDatabase 2022-02-12 23:47:08 +05:30
Aravinth Manivannan 28bbdaebad feat: setup tests 2022-02-12 18:25:45 +05:30
Aravinth Manivannan aa4d205742 fix: apply lints suggested by clippy 2022-02-12 18:25:03 +05:30
Aravinth Manivannan b28a7d0cfb feat: bootstrap database ops
- db-core: defines base database traits that are required for gists
- db-sqlx-postgres: implements db-core for postgres flavor of the sqlx
- db-sqlx-sqlite: implements db-core for sqlite flavor of the sqlx
2022-02-12 16:35:55 +05:30
Aravinth Manivannan 4858f050e7 feat: CI: run tests against DB 2022-02-12 16:31:55 +05:30
Aravinth Manivannan e10451f01f feat: ecosystem overview 2022-02-12 16:31:00 +05:30
Aravinth Manivannan a3c82bf282 setup CI 2022-02-11 17:42:44 +05:30
Aravinth Manivannan 85ab813816 init 2022-02-11 17:42:35 +05:30
Aravinth Manivannan 5d451ec375 add license 2022-02-11 17:42:13 +05:30
Aravinth Manivannan d7fbc2f1d8 add readme 2022-02-11 17:41:54 +05:30