Added preference fields for web theme
This commit is contained in:
parent
2de5b34a48
commit
59366c6b03
7 changed files with 112 additions and 74 deletions
docs/swagger
migrations/2020-01-08-231420_add_theme
src
|
@ -854,6 +854,12 @@
|
|||
"properties": {
|
||||
"lastfm_username": {
|
||||
"type": "string"
|
||||
},
|
||||
"web_theme_base": {
|
||||
"type": "string"
|
||||
},
|
||||
"web_theme_accent": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
14
migrations/2020-01-08-231420_add_theme/down.sql
Normal file
14
migrations/2020-01-08-231420_add_theme/down.sql
Normal file
|
@ -0,0 +1,14 @@
|
|||
CREATE TEMPORARY TABLE users_backup(id, name, password_hash, admin, lastfm_username, lastfm_session_key);
|
||||
INSERT INTO users_backup SELECT id, name, password_hash, admin, lastfm_username, lastfm_session_key FROM users;
|
||||
DROP TABLE users;
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
password_hash TEXT NOT NULL,
|
||||
admin INTEGER NOT NULL,
|
||||
lastfm_username TEXT,
|
||||
lastfm_session_key TEXT,
|
||||
UNIQUE(name)
|
||||
);
|
||||
INSERT INTO users SELECT * FROM users_backup;
|
||||
DROP TABLE users_backup;
|
2
migrations/2020-01-08-231420_add_theme/up.sql
Normal file
2
migrations/2020-01-08-231420_add_theme/up.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users ADD COLUMN web_theme_base TEXT;
|
||||
ALTER TABLE users ADD COLUMN web_theme_accent TEXT;
|
|
@ -25,7 +25,7 @@ use crate::utils;
|
|||
use crate::vfs::VFSSource;
|
||||
|
||||
const CURRENT_MAJOR_VERSION: i32 = 3;
|
||||
const CURRENT_MINOR_VERSION: i32 = 0;
|
||||
const CURRENT_MINOR_VERSION: i32 = 1;
|
||||
const COOKIE_SESSION: &str = "session";
|
||||
|
||||
pub fn get_routes() -> Vec<rocket::Route> {
|
||||
|
|
|
@ -58,7 +58,7 @@ fn version() {
|
|||
|
||||
let response_body = response.body_string().unwrap();
|
||||
let response_json: api::Version = serde_json::from_str(&response_body).unwrap();
|
||||
assert_eq!(response_json, api::Version { major: 3, minor: 0 });
|
||||
assert_eq!(response_json, api::Version { major: 3, minor: 1 });
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -28,6 +28,8 @@ pub struct MiscSettings {
|
|||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Preferences {
|
||||
pub lastfm_username: Option<String>,
|
||||
pub web_theme_base: Option<String>,
|
||||
pub web_theme_accent: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -250,19 +252,29 @@ where
|
|||
{
|
||||
use self::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
let read_lastfm_username = users
|
||||
.select(lastfm_username)
|
||||
let (theme_base, theme_accent, read_lastfm_username) = users
|
||||
.select((web_theme_base, web_theme_accent, lastfm_username))
|
||||
.filter(name.eq(username))
|
||||
.get_result(connection.deref())?;
|
||||
Ok(Preferences {
|
||||
web_theme_base: theme_base,
|
||||
web_theme_accent: theme_accent,
|
||||
lastfm_username: read_lastfm_username,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn write_preferences<T>(_: &T, _: &str, _: &Preferences) -> Result<()>
|
||||
pub fn write_preferences<T>(db: &T, username: &str, preferences: &Preferences) -> Result<()>
|
||||
where
|
||||
T: ConnectionSource,
|
||||
{
|
||||
use crate::db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
diesel::update(users.filter(name.eq(username)))
|
||||
.set((
|
||||
web_theme_base.eq(&preferences.web_theme_base),
|
||||
web_theme_accent.eq(&preferences.web_theme_accent),
|
||||
))
|
||||
.execute(connection.deref())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -533,6 +545,8 @@ fn test_preferences_read_write() {
|
|||
amend(&db, &initial_config).unwrap();
|
||||
|
||||
let new_preferences = Preferences {
|
||||
web_theme_base: Some("very-dark-theme".to_owned()),
|
||||
web_theme_accent: Some("#FF0000".to_owned()),
|
||||
lastfm_username: None,
|
||||
};
|
||||
write_preferences(&db, "Teddy🐻", &new_preferences).unwrap();
|
||||
|
|
140
src/db/schema.rs
140
src/db/schema.rs
|
@ -1,98 +1,100 @@
|
|||
table! {
|
||||
ddns_config (id) {
|
||||
id -> Integer,
|
||||
host -> Text,
|
||||
username -> Text,
|
||||
password -> Text,
|
||||
}
|
||||
ddns_config (id) {
|
||||
id -> Integer,
|
||||
host -> Text,
|
||||
username -> Text,
|
||||
password -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
directories (id) {
|
||||
id -> Integer,
|
||||
path -> Text,
|
||||
parent -> Nullable<Text>,
|
||||
artist -> Nullable<Text>,
|
||||
year -> Nullable<Integer>,
|
||||
album -> Nullable<Text>,
|
||||
artwork -> Nullable<Text>,
|
||||
date_added -> Integer,
|
||||
}
|
||||
directories (id) {
|
||||
id -> Integer,
|
||||
path -> Text,
|
||||
parent -> Nullable<Text>,
|
||||
artist -> Nullable<Text>,
|
||||
year -> Nullable<Integer>,
|
||||
album -> Nullable<Text>,
|
||||
artwork -> Nullable<Text>,
|
||||
date_added -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
misc_settings (id) {
|
||||
id -> Integer,
|
||||
auth_secret -> Binary,
|
||||
index_sleep_duration_seconds -> Integer,
|
||||
index_album_art_pattern -> Text,
|
||||
prefix_url -> Text,
|
||||
}
|
||||
misc_settings (id) {
|
||||
id -> Integer,
|
||||
auth_secret -> Binary,
|
||||
index_sleep_duration_seconds -> Integer,
|
||||
index_album_art_pattern -> Text,
|
||||
prefix_url -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
mount_points (id) {
|
||||
id -> Integer,
|
||||
source -> Text,
|
||||
name -> Text,
|
||||
}
|
||||
mount_points (id) {
|
||||
id -> Integer,
|
||||
source -> Text,
|
||||
name -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
playlist_songs (id) {
|
||||
id -> Integer,
|
||||
playlist -> Integer,
|
||||
path -> Text,
|
||||
ordering -> Integer,
|
||||
}
|
||||
playlist_songs (id) {
|
||||
id -> Integer,
|
||||
playlist -> Integer,
|
||||
path -> Text,
|
||||
ordering -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
playlists (id) {
|
||||
id -> Integer,
|
||||
owner -> Integer,
|
||||
name -> Text,
|
||||
}
|
||||
playlists (id) {
|
||||
id -> Integer,
|
||||
owner -> Integer,
|
||||
name -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
songs (id) {
|
||||
id -> Integer,
|
||||
path -> Text,
|
||||
parent -> Text,
|
||||
track_number -> Nullable<Integer>,
|
||||
disc_number -> Nullable<Integer>,
|
||||
title -> Nullable<Text>,
|
||||
artist -> Nullable<Text>,
|
||||
album_artist -> Nullable<Text>,
|
||||
year -> Nullable<Integer>,
|
||||
album -> Nullable<Text>,
|
||||
artwork -> Nullable<Text>,
|
||||
duration -> Nullable<Integer>,
|
||||
}
|
||||
songs (id) {
|
||||
id -> Integer,
|
||||
path -> Text,
|
||||
parent -> Text,
|
||||
track_number -> Nullable<Integer>,
|
||||
disc_number -> Nullable<Integer>,
|
||||
title -> Nullable<Text>,
|
||||
artist -> Nullable<Text>,
|
||||
album_artist -> Nullable<Text>,
|
||||
year -> Nullable<Integer>,
|
||||
album -> Nullable<Text>,
|
||||
artwork -> Nullable<Text>,
|
||||
duration -> Nullable<Integer>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
users (id) {
|
||||
id -> Integer,
|
||||
name -> Text,
|
||||
password_hash -> Text,
|
||||
admin -> Integer,
|
||||
lastfm_username -> Nullable<Text>,
|
||||
lastfm_session_key -> Nullable<Text>,
|
||||
}
|
||||
users (id) {
|
||||
id -> Integer,
|
||||
name -> Text,
|
||||
password_hash -> Text,
|
||||
admin -> Integer,
|
||||
lastfm_username -> Nullable<Text>,
|
||||
lastfm_session_key -> Nullable<Text>,
|
||||
web_theme_base -> Nullable<Text>,
|
||||
web_theme_accent -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
joinable!(playlist_songs -> playlists (playlist));
|
||||
joinable!(playlists -> users (owner));
|
||||
|
||||
allow_tables_to_appear_in_same_query!(
|
||||
ddns_config,
|
||||
directories,
|
||||
misc_settings,
|
||||
mount_points,
|
||||
playlist_songs,
|
||||
playlists,
|
||||
songs,
|
||||
users,
|
||||
ddns_config,
|
||||
directories,
|
||||
misc_settings,
|
||||
mount_points,
|
||||
playlist_songs,
|
||||
playlists,
|
||||
songs,
|
||||
users,
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue