Commit Graph
42 Commits
Author SHA1 Message Date
ff0c82efc1 review by @fdb-hiroshima
Co-Authored-By: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com>
2019-08-14 23:51:27 +02:00
60270121dc fix clippy warning
Co-Authored-By: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com>
2019-08-14 23:51:26 +02:00
Igor GalićandIgor Galić 2dedcdbc53 start modifying /blogs/new to add custom_domain to the form 2019-08-14 23:51:24 +02:00
Igor GalićandIgor Galić 6cd8bd89b2 fix syntax: we're now down to type errors 2019-08-14 23:51:22 +02:00
Igor GalićandIgor Galić f635dcf6c3 move custom_ route functions into a custom namespace
this way, we can actually use the url! macro
2019-08-14 23:51:20 +02:00
Igor GalićandIgor Galić 203da23cf2 follow up on @fdb-hiroshima & @BaptisteGelez review 2019-08-14 23:51:19 +02:00
Igor GalićandIgor Galić f73fba583a custom_domainify posts::details 2019-08-14 23:51:18 +02:00
Igor GalićandIgor Galić fe110b5d8a fix issues pointed out by @BaptisteGelez in review 2019-08-14 23:51:17 +02:00
Igor GalićandIgor Galić cc0df4ecb2 redirect blog urls to custom_domain if it exists 2019-08-14 23:51:16 +02:00
Igor GalićandIgor Galić 9cee38ae6a add url to Blog, this seems useful. 2019-08-14 23:51:16 +02:00
Igor GalićandIgor Galić 8e7f789969 Allow searching from custom_domain 2019-08-14 23:51:15 +02:00
Igor GalićandIgor Galić 92fbd174eb extend 404 handler to handle all the requests our custom_ routes dont 2019-08-14 23:51:14 +02:00
Igor GalićandIgor Galić 6253adf768 simplify / unify error handling
We want to return a Result<Blog>, instead of a QueryResult<Blog>.
We can use map_err() to map it to the desired error type.

thanks to review from @BaptisteGelez & @fdb-hiroshima.
2019-08-14 23:51:13 +02:00
Igor GalićandIgor Galić a0aef50674 extract common routing code into private "_guts()" functions 2019-08-14 23:51:13 +02:00
Igor GalićandIgor Galić 8e6b1ab86e simplify retrieval in find_by_host()
we can use "first()" instead of limit(1).load().etc…
since on a UNIQUE field, we only expect 1 result.

first() returns QueryResult, which is Result<T, diesel::Error>, so we
need to implement a converter for that error type.

This commit addresses @fdb-hiroshima's review.
2019-08-14 23:51:12 +02:00
Igor GalićandIgor Galić 1c34ac38f7 replace if / else with ok_or() 2019-08-14 23:51:11 +02:00
Igor GalićandIgor Galić 468e663344 Add custom_details and custom_activity_details as first routes
how this works: we use find_by_host() to find the Host in question, the
defer to the existing function!

Caveat: Currently, we, in that function, we do another lookup DB lookup
for the Blog, even thou we already know it.
It might be wise, to have both of those another wrapper here?!
2019-08-14 23:51:10 +02:00
Igor GalićandIgor Galić 0645f7e253 CustomDomainFairing must not match /static/ and /api/
thanks, again, @fdb-hiroshima for helping with this code, when i got
stuck in lifetime-hecc.
2019-08-14 23:51:10 +02:00
Igor GalićandIgor Galić f94b0c79c5 move impl closer to mother struct 2019-08-14 23:51:09 +02:00
Igor GalićandIgor Galić b09b51c74b normalize URLs before setting them 2019-08-14 23:51:08 +02:00
Igor GalićandIgor Galić e6747de998 cache custom_domains list
follow #572 and cache the list of custom domains.
2019-08-14 23:51:07 +02:00
Igor GalićandIgor Galić 2746e088ae appease clippy 2019-08-14 23:51:06 +02:00
Igor GalićandIgor Galić 3a4c2f2cf9 create & attach an AdHoc Fairing for dealing with Custom Domains
this rewrites the URL to /custom_domain/<url>
(we have no route handlers for this path yet)

Lots of help from @fdb-hiroshima & @BaptisteGelez in dealing with the
borrow checker — thank you 💜
2019-08-14 23:51:06 +02:00
Igor GalićandIgor Galić 351c01f71c list custom_domains
thanks a lot to @fdb-hiroshima and @BaptisteGelez for helping with the
code.
2019-08-14 23:51:05 +02:00
Igor GalićandIgor Galić 65ae51b7e5 implement Host more completely by doing less
we now use DieselNewType and Shrinkwrap to automatically derive all the
things we need.
2019-08-14 23:51:04 +02:00
Igor GalićandIgor Galić 92bbeeb45e add Host(String) wrapper type
we can use this to handle rocket Requests (from_request)
but we still have to figure out how to automatically assign the type to
custom_domain: Optional<Host>, and public_domain: Host.
2019-08-14 23:51:03 +02:00
Igor GalićandIgor Galić 6bcc4f0ab0 add custom_domain (default to NULL) to schema 2019-08-14 23:51:03 +02:00
Igor GalićandGitHub 3d27e283ad add enum containing all successful route returns (#614)
* add enum containing all successful route returns

This enum derives `Responder`, so it can be used as route result.
We also implement `From`, so it can be converted

* disable clippy warning about this enum

There's no use trying to chase this warning.
The next warning will be about `Redirect`, which itself is 360 byte,
according to @fdb-hiroshima (thanks for the research!)

So, if anything, we can try to get Rocket to work on that!

* refactor routes/posts to only use one level of Result

* admin settings error is not an ErrorPage, so dont use Result<>

* refactor: use early return to remove indent of main logic

This diff is absolutely atrocious.
but the resulting readability is worth it

* refactor routes/post for early returns & RespondOrRedirect

* refactor routes/session for early returns & use RespondOrRedirect

* refactor routes/user -- add another field to enum

* refactor routes/blogs for early returns & RespondOrRedirect

* refactor routes/blogs for early returns & RespondOrRedirect

This is a final refactor of `pub fn update()` for readability.
We're removing at least one indentation level.
2019-06-14 09:33:30 +02:00
Igor GalićandBaptiste Gelez 8c59c822b6 refactor code to use Shrinkwraprs and diesel-derive-newtype (#598)
* add shrinkwraprs and implement Id thru it

This also means we can automatically convert Id to String without using
.into()!

* cleanup with the help of clippy!

* cleanup with the help of cargo fmt!

* remove extra block

* Shrinkwrap Page, ContentLen and RemoteForm

* translations
2019-05-25 19:23:45 +01:00
Igor GalićandBaptiste Gelez 732f514da7 Refactor with the help of Clippy (#462)
We add clippy as our build — also rectifying the missing `plume-cli` build!

In the next step we follow clippy's advise and fix some of the "simple" mistakes in our code, such as style or map usage.

Finally, we refactor some hard bits that need extraction of new types, or refactoring of function call-types, especially those that thread thru macros, and, of course functions with ~15 parameters should probably be rethought.
2019-03-19 14:37:56 +01:00
Igor Galić 88456faf84 align types between sqlite & postgres
this one's achieved by adding "NOT NULL" at the *correct* position in
SQLite's create tables.
2018-09-30 14:13:53 +02:00
Igor Galić b28bef20a7 align types between sqlite & postgres
use DATETIME for SQLite's time type. This way, Diesel picks up on what
it's supposed to be.
2018-09-30 14:13:52 +02:00
Igor Galić 1f8680c4c5 add sqlite migrations
we move our PostgreSQL specific migrations to a subdirectory.
The SQLite migrations have been created by running `diesel` against a
copy, and then fixing what's broken.
In the end i reduced all modifications to a single create, since we
*are* starting out fresh with SQLite.

n.b.: i'm not entirely happy with the results yet, because diesel
heavily modifies our `plume-models/src/schema.rs`.
I'll keep fiddling until we have the same types between the two
databases.
2018-09-30 14:13:52 +02:00
Igor Galić e5691f7b23 add sqlite as diesel dependency 2018-09-30 14:13:42 +02:00
Igor Galić fb074e6344 render SafeString thru |safe
thanks again to @fdb-hiroshima for pointing me in the right direction!
2018-09-14 21:44:32 +02:00
Igor Galić 06718a5c8a directly use SafeString in InstanceSettingsForm 2018-09-14 20:25:16 +02:00
Igor Galić d62c72dde0 allocate new SafeString in FromFormValue impl
thanks to @fdb-hiroshima for this review!
2018-09-14 19:50:59 +02:00
Igor Galić 0897088aa5 add implementation for FromFormValue for SafeString
thanks again to @pwoolcoc for this!
2018-09-14 18:26:42 +02:00
Igor Galić 65e213309b do not allocate empty strings
follow review from @pwoolcoc, and do not use

    SafeString::new(&<String>::new())

since this makes an allocation which will then just be thrown away.
Instead, we pass ""
2018-09-14 18:24:27 +02:00
Igor Galić f5c299f23c make blog/instance description a SafeString
long_description & short_description's documentation say they can be
Markdown, but they are String, not SafeString.

This led to escaped strings being printed in the editor
https://github.com/Plume-org/Plume/issues/220
2018-09-14 15:14:24 +02:00
Igor Galić e7b5d81687 gitignore docker-compose.yml 2018-09-13 17:21:20 +02:00
Igor Galić dfc76757bb fix comment in docker.sample.env
docker's sample .env file under docs/ which contains the wrong command
to generate a rocket secret_key
2018-09-13 17:18:25 +02:00