-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: persist user content restriction
- Loading branch information
Showing
4 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
komga/src/flyway/resources/db/migration/sqlite/V20220225164240__user_restrictions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE USER_SHARING | ||
( | ||
LABEL varchar NOT NULL, | ||
ALLOW boolean NOT NULL, | ||
USER_ID varchar NOT NULL, | ||
PRIMARY KEY (LABEL, ALLOW, USER_ID), | ||
FOREIGN KEY (USER_ID) REFERENCES USER (ID) | ||
); | ||
|
||
ALTER TABLE USER | ||
add column AGE_RESTRICTION integer NULL; | ||
ALTER TABLE USER | ||
add column AGE_RESTRICTION_ALLOW_ONLY boolean NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package org.gotson.komga.infrastructure.jooq | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.gotson.komga.domain.model.ContentRestriction | ||
import org.gotson.komga.domain.model.ContentRestrictions | ||
import org.gotson.komga.domain.model.KomgaUser | ||
import org.gotson.komga.domain.model.makeLibrary | ||
import org.gotson.komga.domain.persistence.LibraryRepository | ||
|
@@ -59,9 +61,12 @@ class KomgaUserDaoTest( | |
assertThat(lastModifiedDate).isCloseTo(now, offset) | ||
assertThat(email).isEqualTo("[email protected]") | ||
assertThat(password).isEqualTo("password") | ||
assertThat(roleAdmin).isFalse() | ||
assertThat(roleAdmin).isFalse | ||
assertThat(sharedLibrariesIds).containsExactly(library.id) | ||
assertThat(sharedAllLibraries).isFalse() | ||
assertThat(sharedAllLibraries).isFalse | ||
assertThat(restrictions.ageRestriction).isNull() | ||
assertThat(restrictions.labelsAllowRestriction).isNull() | ||
assertThat(restrictions.labelsExcludeRestriction).isNull() | ||
} | ||
} | ||
|
||
|
@@ -73,17 +78,41 @@ class KomgaUserDaoTest( | |
roleAdmin = false, | ||
sharedLibrariesIds = setOf(library.id), | ||
sharedAllLibraries = false, | ||
restrictions = ContentRestrictions( | ||
ageRestriction = ContentRestriction.AgeRestriction.AllowOnlyUnder(10), | ||
labelsAllow = setOf("allow"), | ||
labelsExclude = setOf("exclude"), | ||
) | ||
) | ||
|
||
komgaUserDao.insert(user) | ||
val created = komgaUserDao.findByIdOrNull(user.id)!! | ||
with(created) { | ||
assertThat(restrictions.ageRestriction) | ||
.isNotNull | ||
.isExactlyInstanceOf(ContentRestriction.AgeRestriction.AllowOnlyUnder::class.java) | ||
assertThat(restrictions.ageRestriction!!.age).isEqualTo(10) | ||
assertThat(restrictions.labelsAllowRestriction) | ||
.isNotNull | ||
.isExactlyInstanceOf(ContentRestriction.LabelsRestriction.AllowOnly::class.java) | ||
assertThat(restrictions.labelsAllowRestriction!!.labels).containsExactly("allow") | ||
assertThat(restrictions.labelsExcludeRestriction) | ||
.isNotNull | ||
.isExactlyInstanceOf(ContentRestriction.LabelsRestriction.Exclude::class.java) | ||
assertThat(restrictions.labelsExcludeRestriction!!.labels).containsExactly("exclude") | ||
} | ||
|
||
val modified = created.copy( | ||
email = "[email protected]", | ||
password = "password2", | ||
roleAdmin = true, | ||
sharedLibrariesIds = emptySet(), | ||
sharedAllLibraries = true, | ||
restrictions = ContentRestrictions( | ||
ageRestriction = ContentRestriction.AgeRestriction.ExcludeOver(16), | ||
labelsAllow = setOf("allow2"), | ||
labelsExclude = setOf("exclude2"), | ||
), | ||
) | ||
val modifiedDate = LocalDateTime.now() | ||
komgaUserDao.update(modified) | ||
|
@@ -97,9 +126,28 @@ class KomgaUserDaoTest( | |
.isNotEqualTo(modified.createdDate) | ||
assertThat(email).isEqualTo("[email protected]") | ||
assertThat(password).isEqualTo("password2") | ||
assertThat(roleAdmin).isTrue() | ||
assertThat(roleAdmin).isTrue | ||
assertThat(sharedLibrariesIds).isEmpty() | ||
assertThat(sharedAllLibraries).isTrue() | ||
assertThat(sharedAllLibraries).isTrue | ||
assertThat(restrictions.ageRestriction) | ||
.isNotNull | ||
.isExactlyInstanceOf(ContentRestriction.AgeRestriction.ExcludeOver::class.java) | ||
assertThat(restrictions.ageRestriction!!.age).isEqualTo(16) | ||
assertThat(restrictions.labelsAllowRestriction) | ||
.isNotNull | ||
.isExactlyInstanceOf(ContentRestriction.LabelsRestriction.AllowOnly::class.java) | ||
assertThat(restrictions.labelsAllowRestriction!!.labels).containsExactly("allow2") | ||
assertThat(restrictions.labelsExcludeRestriction) | ||
.isNotNull | ||
.isExactlyInstanceOf(ContentRestriction.LabelsRestriction.Exclude::class.java) | ||
assertThat(restrictions.labelsExcludeRestriction!!.labels).containsExactly("exclude2") | ||
} | ||
|
||
komgaUserDao.update(modifiedSaved.copy(restrictions = ContentRestrictions())) | ||
with(komgaUserDao.findByIdOrNull(modified.id)!!) { | ||
assertThat(restrictions.ageRestriction).isNull() | ||
assertThat(restrictions.labelsAllowRestriction).isNull() | ||
assertThat(restrictions.labelsExcludeRestriction).isNull() | ||
} | ||
} | ||
|
||
|