Rewrite article publication with the REST API

- Add a default App and ApiToken for each user, that is used by the front-end
- Add an API route to update an article (CSRF had to be disabled because of a bug in rocket_csrf)
- Use AJAX to publish and edit articles in the new editor, instead of weird hacks with HTML forms
This commit is contained in:
Ana Gelez
2019-08-03 23:04:25 +02:00
parent 4142e73018
commit cc998e7c61
17 changed files with 372 additions and 162 deletions
+12
View File
@@ -44,6 +44,18 @@ impl ApiToken {
get!(api_tokens);
insert!(api_tokens, NewApiToken);
find_by!(api_tokens, find_by_value, value as &str);
find_by!(
api_tokens,
find_by_app_and_user,
app_id as i32,
user_id as i32
);
/// The token for Plume's front-end
pub fn web_token(conn: &crate::Connection, user_id: i32) -> Result<ApiToken> {
let app = crate::apps::App::find_by_name(conn, "Plume web interface")?;
Self::find_by_app_and_user(conn, app.id, user_id)
}
pub fn can(&self, what: &'static str, scope: &'static str) -> bool {
let full_scope = what.to_owned() + ":" + scope;
+1
View File
@@ -29,4 +29,5 @@ impl App {
get!(apps);
insert!(apps, NewApp);
find_by!(apps, find_by_client_id, client_id as &str);
find_by!(apps, find_by_name, name as &str);
}
+1
View File
@@ -64,6 +64,7 @@ pub enum Error {
Signature,
Unauthorized,
Url,
Validation(String),
Webfinger,
Expired,
}