Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Flush #3446

Merged
merged 13 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/develop-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
- name: Compile dotnet app
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 8.0.x

- name: Install Swashbuckle CLI
run: dotnet tool install -g Swashbuckle.AspNetCore.Cli
Expand All @@ -137,6 +137,7 @@ jobs:

- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ github.repository_owner == 'Kareadita' }}
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
Expand All @@ -155,20 +156,33 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: docker_meta_nightly
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=nightly
type=raw,value=nightly-${{ steps.parse-version.outputs.VERSION }}
images: |
name=jvmilazz0/kavita,enable=${{ github.repository_owner == 'Kareadita' }}
name=ghcr.io/${{ github.repository }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: jvmilazz0/kavita:nightly, jvmilazz0/kavita:nightly-${{ steps.parse-version.outputs.VERSION }}, ghcr.io/kareadita/kavita:nightly, ghcr.io/kareadita/kavita:nightly-${{ steps.parse-version.outputs.VERSION }}
tags: ${{ steps.docker_meta_nightly.outputs.tags }}
labels: ${{ steps.docker_meta_nightly.outputs.labels }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

- name: Notify Discord
uses: rjstone/discord-webhook-notify@v1
if: ${{ github.repository_owner == 'Kareadita' }}
with:
severity: info
description: v${{steps.get-version.outputs.assembly-version}} - ${{ steps.findPr.outputs.title }}
Expand Down
33 changes: 29 additions & 4 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ jobs:

- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ github.repository_owner == 'Kareadita' }}
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
Expand All @@ -132,23 +133,47 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (tags, labels) for Docker
id: docker_meta_stable
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=latest
type=raw,value=${{ steps.parse-version.outputs.VERSION }}
images: |
name=jvmilazz0/kavita,enable=${{ github.repository_owner == 'Kareadita' }}
name=ghcr.io/${{ github.repository }}

- name: Build and push stable
id: docker_build_stable
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: jvmilazz0/kavita:latest, jvmilazz0/kavita:${{ steps.parse-version.outputs.VERSION }}, ghcr.io/kareadita/kavita:latest, ghcr.io/kareadita/kavita:${{ steps.parse-version.outputs.VERSION }}
tags: ${{ steps.docker_meta_stable.outputs.tags }}
labels: ${{ steps.docker_meta_stable.outputs.labels }}

- name: Extract metadata (tags, labels) for Docker
id: docker_meta_nightly
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=nightly
type=raw,value=nightly-${{ steps.parse-version.outputs.VERSION }}
images: |
name=jvmilazz0/kavita,enable=${{ github.repository_owner == 'Kareadita' }}
name=ghcr.io/${{ github.repository }}

- name: Build and push nightly
id: docker_build_nightly
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: jvmilazz0/kavita:nightly, jvmilazz0/kavita:nightly-${{ steps.parse-version.outputs.VERSION }}, ghcr.io/kareadita/kavita:nightly, ghcr.io/kareadita/kavita:nightly-${{ steps.parse-version.outputs.VERSION }}
tags: ${{ steps.docker_meta_nightly.outputs.tags }}
labels: ${{ steps.docker_meta_nightly.outputs.labels }}

- name: Image digest
run: echo ${{ steps.docker_build_stable.outputs.digest }}
Expand Down
8 changes: 4 additions & 4 deletions API.Tests/Extensions/QueryableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ public void RestrictAgainstAgeRestriction_Tag_ShouldRestrictEverythingAboveTeen(

[Theory]
[InlineData(true, 2)]
[InlineData(false, 1)]
public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedCount)
[InlineData(false, 2)]
public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedPeopleCount)
{
// Arrange
var items = new List<Person>
{
CreatePersonWithSeriesMetadata("Test1", AgeRating.Teen),
CreatePersonWithSeriesMetadata("Test2", AgeRating.Unknown, AgeRating.Teen),
CreatePersonWithSeriesMetadata("Test2", AgeRating.Unknown, AgeRating.Teen), // 2 series on this person, restrict will still allow access
CreatePersonWithSeriesMetadata("Test3", AgeRating.X18Plus)
};

Expand All @@ -144,7 +144,7 @@ public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTe
var filtered = items.AsQueryable().RestrictAgainstAgeRestriction(ageRestriction);

// Assert
Assert.Equal(expectedCount, filtered.Count());
Assert.Equal(expectedPeopleCount, filtered.Count());
}

private static Person CreatePersonWithSeriesMetadata(string name, params AgeRating[] ageRatings)
Expand Down
20 changes: 17 additions & 3 deletions API/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,21 @@ public async Task<ActionResult> UpdateAccount(UpdateUserDto dto)
_unitOfWork.UserRepository.Update(user);
}

// Check if email is changing for a non-admin user
var isUpdatingAnotherAccount = user.Id != adminUser.Id;
if (isUpdatingAnotherAccount && !string.IsNullOrEmpty(dto.Email) && user.Email != dto.Email)
{
// Validate username change
var errors = await _accountService.ValidateEmail(dto.Email);
if (errors.Any()) return BadRequest(await _localizationService.Translate(User.GetUserId(), "email-taken"));

user.Email = dto.Email;
user.EmailConfirmed = true; // When an admin performs the flow, we assume the email address is able to receive data

await _userManager.UpdateNormalizedEmailAsync(user);
_unitOfWork.UserRepository.Update(user);
}

// Update roles
var existingRoles = await _userManager.GetRolesAsync(user);
var hasAdminRole = dto.Roles.Contains(PolicyConstants.AdminRole);
Expand Down Expand Up @@ -612,8 +627,7 @@ public async Task<ActionResult<string>> InviteUser(InviteUserDto dto)
if (adminUser == null) return Unauthorized(await _localizationService.Translate(userId, "permission-denied"));

dto.Email = dto.Email.Trim();
if (string.IsNullOrEmpty(dto.Email))
return BadRequest(await _localizationService.Translate(userId, "invalid-payload"));
if (string.IsNullOrEmpty(dto.Email)) return BadRequest(await _localizationService.Translate(userId, "invalid-payload"));

_logger.LogInformation("{User} is inviting {Email} to the server", adminUser.UserName, dto.Email);

Expand All @@ -623,7 +637,7 @@ public async Task<ActionResult<string>> InviteUser(InviteUserDto dto)
{
var invitedUser = await _unitOfWork.UserRepository.GetUserByEmailAsync(dto.Email);
if (await _userManager.IsEmailConfirmedAsync(invitedUser!))
return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-already-registered", invitedUser.UserName));
return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-already-registered", invitedUser!.UserName));
return BadRequest(await _localizationService.Translate(User.GetUserId(), "user-already-invited"));
}

Expand Down
4 changes: 4 additions & 0 deletions API/DTOs/Account/UpdateUserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public record UpdateUserDto
/// An Age Rating which will limit the account to seeing everything equal to or below said rating.
/// </summary>
public AgeRestrictionDto AgeRestriction { get; init; } = default!;
/// <summary>
/// Email of the user
/// </summary>
public string? Email { get; set; } = default!;
}
11 changes: 7 additions & 4 deletions API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ public static IQueryable<Person> RestrictAgainstAgeRestriction(this IQueryable<P

if (restriction.IncludeUnknowns)
{
return queryable.Where(c => c.SeriesMetadataPeople.All(sm =>
sm.SeriesMetadata.AgeRating <= restriction.AgeRating));
return queryable.Where(c =>
c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating) ||
c.ChapterPeople.Any(cp => cp.Chapter.AgeRating <= restriction.AgeRating));
}

return queryable.Where(c => c.SeriesMetadataPeople.All(sm =>
sm.SeriesMetadata.AgeRating <= restriction.AgeRating && sm.SeriesMetadata.AgeRating > AgeRating.Unknown));
return queryable.Where(c =>
c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating && sm.SeriesMetadata.AgeRating != AgeRating.Unknown) ||
c.ChapterPeople.Any(cp => cp.Chapter.AgeRating <= restriction.AgeRating && cp.Chapter.AgeRating != AgeRating.Unknown)
);
}

public static IQueryable<ReadingList> RestrictAgainstAgeRestriction(this IQueryable<ReadingList> queryable, AgeRestriction restriction)
Expand Down
1 change: 1 addition & 0 deletions API/I18N/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"age-restriction-update": "There was an error updating the age restriction",
"no-user": "User does not exist",
"username-taken": "Username already taken",
"email-taken": "Email already in use",
"user-already-confirmed": "User is already confirmed",
"generic-user-update": "There was an exception when updating the user",
"manual-setup-fail": "Manual setup is unable to be completed. Please cancel and recreate the invite",
Expand Down
8 changes: 4 additions & 4 deletions API/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public async Task<IEnumerable<ApiException>> ValidateUsername(string username)
public async Task<IEnumerable<ApiException>> ValidateEmail(string email)
{
var user = await _unitOfWork.UserRepository.GetUserByEmailAsync(email);
if (user == null) return Array.Empty<ApiException>();
if (user == null) return [];

return new List<ApiException>()
{
return
[
new ApiException(400, "Email is already registered")
};
];
}

/// <summary>
Expand Down
19 changes: 11 additions & 8 deletions API/Services/Tasks/StatsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using API.Entities;
using API.Entities.Enums;
using API.Services.Plus;
using API.Services.Tasks.Scanner.Parser;
using Flurl.Http;
using Kavita.Common.EnvironmentInfo;
using Kavita.Common.Helpers;
Expand Down Expand Up @@ -231,11 +232,12 @@ private async Task<int> MaxChaptersInASeries()
{
// If first time flow, just return 0
if (!await _context.Chapter.AnyAsync()) return 0;

return await _context.Series
.AsNoTracking()
.AsSplitQuery()
.MaxAsync(s => s.Volumes!
.Where(v => v.MinNumber == 0)
.Where(v => v.MinNumber == Parser.LooseLeafVolumeNumber)
.SelectMany(v => v.Chapters!)
.Count());
}
Expand All @@ -262,13 +264,13 @@ private async Task<ServerInfoV3Dto> GetStatV3Payload()
dto.MaxSeriesInALibrary = await MaxSeriesInAnyLibrary();
dto.MaxVolumesInASeries = await MaxVolumesInASeries();
dto.MaxChaptersInASeries = await MaxChaptersInASeries();
dto.TotalFiles = await _unitOfWork.LibraryRepository.GetTotalFiles();
dto.TotalGenres = await _unitOfWork.GenreRepository.GetCountAsync();
dto.TotalPeople = await _unitOfWork.PersonRepository.GetCountAsync();
dto.TotalSeries = await _unitOfWork.SeriesRepository.GetCountAsync();
dto.TotalLibraries = (await _unitOfWork.LibraryRepository.GetLibrariesAsync()).Count();
dto.NumberOfCollections = (await _unitOfWork.CollectionTagRepository.GetAllCollectionsAsync()).Count();
dto.NumberOfReadingLists = await _unitOfWork.ReadingListRepository.Count();
dto.TotalFiles = await _context.MangaFile.CountAsync();
dto.TotalGenres = await _context.Genre.CountAsync();
dto.TotalPeople = await _context.Person.CountAsync();
dto.TotalSeries = await _context.Series.CountAsync();
dto.TotalLibraries = await _context.Library.CountAsync();
dto.NumberOfCollections = await _context.AppUserCollection.CountAsync();
dto.NumberOfReadingLists = await _context.ReadingList.CountAsync();

try
{
Expand Down Expand Up @@ -314,6 +316,7 @@ private async Task<ServerInfoV3Dto> GetStatV3Payload()
libDto.UsingFolderWatching = library.FolderWatching;
libDto.CreateCollectionsFromMetadata = library.ManageCollections;
libDto.CreateReadingListsFromMetadata = library.ManageReadingLists;
libDto.LibraryType = library.Type;

dto.Libraries.Add(libDto);
}
Expand Down
27 changes: 27 additions & 0 deletions UI/Web/src/app/_directives/dbl-click.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Directive, EventEmitter, HostListener, Output} from '@angular/core';

@Directive({
selector: '[appDblClick]',
standalone: true
})
export class DblClickDirective {

@Output() doubleClick = new EventEmitter<Event>();

private lastTapTime = 0;
private tapTimeout = 300; // Time threshold for a double tap (in milliseconds)

@HostListener('click', ['$event'])
handleClick(event: Event): void {
event.stopPropagation();
event.preventDefault();

const currentTime = new Date().getTime();
if (currentTime - this.lastTapTime < this.tapTimeout) {
// Detected a double click/tap
this.doubleClick.emit(event);
}
this.lastTapTime = currentTime;
}

}
2 changes: 1 addition & 1 deletion UI/Web/src/app/_services/person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PersonService {
}

get(name: string) {
return this.httpClient.get<Person>(this.baseUrl + `person?name=${name}`);
return this.httpClient.get<Person | null>(this.baseUrl + `person?name=${name}`);
}

getRolesForPerson(personId: number) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<ng-container *transloco="let t; read: 'actionable'">
@if (actions.length > 0) {
@if ((utilityService.activeBreakpoint$ | async)! <= Breakpoint.Tablet) {
<button [disabled]="disabled" class="btn {{btnClass}}" id="actions-{{labelBy}}"
<button [disabled]="disabled" class="btn {{btnClass}} px-3" id="actions-{{labelBy}}"
(click)="openMobileActionableMenu($event)">
{{label}}
<i class="fa {{iconClass}}" aria-hidden="true"></i>
</button>
} @else {
<div ngbDropdown container="body" class="d-inline-block">
<button [disabled]="disabled" class="btn {{btnClass}}" id="actions-{{labelBy}}" ngbDropdownToggle
<button [disabled]="disabled" class="btn {{btnClass}} px-3" id="actions-{{labelBy}}" ngbDropdownToggle
(click)="preventEvent($event)">
{{label}}
<i class="fa {{iconClass}}" aria-hidden="true"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h6 class="card-title">
{{review.isExternal ? t('external-review') : t('local-review')}}
</h6>-->
<p class="card-text no-images">
<app-read-more [text]="(review.isExternal ? review.bodyJustText : review.body) || ''" [maxLength]="150" [showToggle]="false"></app-read-more>
<app-read-more [text]="(review.isExternal ? review.bodyJustText : review.body) || ''" [maxLength]="140" [showToggle]="false"></app-read-more>
</p>
</div>
</div>
Expand Down
Loading
Loading