Last FM unlink now correctly unsets credentials. Missing credentials no longer 401

This commit is contained in:
Antoine Gersant 2020-12-17 19:14:05 -08:00
parent d4c78a0a31
commit e5c1d86577
3 changed files with 7 additions and 6 deletions

View file

@ -126,8 +126,9 @@ impl Manager {
pub fn lastfm_unlink(&self, username: &str) -> anyhow::Result<()> {
use crate::db::users::dsl::*;
let connection = self.db.connect()?;
let null: Option<String> = None;
diesel::update(users.filter(name.eq(username)))
.set((lastfm_session_key.eq(""), lastfm_username.eq("")))
.set((lastfm_session_key.eq(&null), lastfm_username.eq(&null)))
.execute(&connection)?;
Ok(())
}

View file

@ -68,7 +68,7 @@ impl ResponseError for APIError {
APIError::OwnAdminPrivilegeRemoval => StatusCode::CONFLICT,
APIError::AudioFileIOError => StatusCode::NOT_FOUND,
APIError::ThumbnailFileIOError => StatusCode::NOT_FOUND,
APIError::LastFMAccountNotLinked => StatusCode::UNAUTHORIZED,
APIError::LastFMAccountNotLinked => StatusCode::NO_CONTENT,
APIError::LastFMLinkContentBase64DecodeError => StatusCode::BAD_REQUEST,
APIError::LastFMLinkContentEncodingError => StatusCode::BAD_REQUEST,
APIError::UserNotFound => StatusCode::NOT_FOUND,

View file

@ -5,7 +5,7 @@ use crate::service::test::{constants::*, protocol, ServiceType, TestService};
use crate::test_name;
#[test]
fn test_lastfm_scrobble_rejects_unlinked_user() {
fn test_lastfm_scrobble_ignores_unlinked_user() {
let mut service = ServiceType::new(&test_name!());
service.complete_initial_setup();
service.login_admin();
@ -18,11 +18,11 @@ fn test_lastfm_scrobble_rejects_unlinked_user() {
let request = protocol::lastfm_scrobble(&path);
let response = service.fetch(&request);
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
assert_eq!(response.status(), StatusCode::NO_CONTENT);
}
#[test]
fn test_lastfm_now_playing_rejects_unlinked_user() {
fn test_lastfm_now_playing_ignores_unlinked_user() {
let mut service = ServiceType::new(&test_name!());
service.complete_initial_setup();
service.login_admin();
@ -35,5 +35,5 @@ fn test_lastfm_now_playing_rejects_unlinked_user() {
let request = protocol::lastfm_now_playing(&path);
let response = service.fetch(&request);
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
assert_eq!(response.status(), StatusCode::NO_CONTENT);
}