Skip to content

Commit

Permalink
Merge branch 'refs/heads/v14/dev' into release/14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iOvergaard committed May 7, 2024
2 parents 4035550 + f65d465 commit 78d93a1
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public GetAuditLogDocumentController(
[MapToApiVersion("1.0")]
[HttpGet("{id:guid}/audit-log")]
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTime? sinceDate = null, int skip = 0, int take = 100)
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
{
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public async Task<IActionResult> AllLogs(
Direction orderDirection = Direction.Descending,
string? filterExpression = null,
[FromQuery(Name = "logLevel")] LogLevel[]? logLevels = null,
DateTime? startDate = null,
DateTime? endDate = null)
DateTimeOffset? startDate = null,
DateTimeOffset? endDate = null)
{
var levels = logLevels?.Select(l => l.ToString()).ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public async Task<IActionResult> AllMessageTemplates(
CancellationToken cancellationToken,
int skip = 0,
int take = 100,
DateTime? startDate = null,
DateTime? endDate = null)
DateTimeOffset? startDate = null,
DateTimeOffset? endDate = null)
{
Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus> messageTemplatesAttempt = await _logViewerService.GetMessageTemplatesAsync(startDate, endDate, skip, take);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public LogLevelCountLogViewerController(ILogViewerService logViewerService, IUmb
[ProducesResponseType(typeof(LogLevelCountsReponseModel), StatusCodes.Status200OK)]
public async Task<IActionResult> LogLevelCounts(
CancellationToken cancellationToken,
DateTime? startDate = null,
DateTime? endDate = null)
DateTimeOffset? startDate = null,
DateTimeOffset? endDate = null)
{
Attempt<LogLevelCounts?, LogViewerOperationStatus> logLevelCountsAttempt =
await _logViewerService.GetLogLevelCountsAsync(startDate, endDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class ValidateLogFileSizeLogViewerController : LogViewerControllerBase
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> CanViewLogs(
CancellationToken cancellationToken,
DateTime? startDate = null,
DateTime? endDate = null)
DateTimeOffset? startDate = null,
DateTimeOffset? endDate = null)
{
Attempt<bool, LogViewerOperationStatus> result = await _logViewerService.CanViewLogsAsync(startDate, endDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GetAuditLogMediaController(
[MapToApiVersion("1.0")]
[HttpGet("{id:guid}/audit-log")]
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTime? sinceDate = null, int skip = 0, int take = 100)
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
{
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class MemberResponseModel : ContentResponseModelBase<MemberValueModel, Me

public int FailedPasswordAttempts { get; set; }

public DateTime? LastLoginDate { get; set; }
public DateTimeOffset? LastLoginDate { get; set; }

public DateTime? LastLockoutDate { get; set; }
public DateTimeOffset? LastLockoutDate { get; set; }

public DateTime? LastPasswordChangeDate { get; set; }
public DateTimeOffset? LastPasswordChangeDate { get; set; }

public IEnumerable<Guid> Groups { get; set; } = [];
}
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Services/AuditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public async Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
int skip,
int take,
Direction orderDirection = Direction.Descending,
DateTime? sinceDate = null,
DateTimeOffset? sinceDate = null,
AuditType[]? auditTypeFilter = null)
{
if (skip < 0)
Expand All @@ -264,7 +264,7 @@ public async Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
using (ScopeProvider.CreateCoreScope(autoComplete: true))
{
IQuery<IAuditItem> query = Query<IAuditItem>().Where(x => x.Id == keyToIdAttempt.Result);
IQuery<IAuditItem>? customFilter = sinceDate.HasValue ? Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate) : null;
IQuery<IAuditItem>? customFilter = sinceDate.HasValue ? Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate.Value.LocalDateTime) : null;
PaginationHelper.ConvertSkipTakeToPaging(skip, take, out var pageNumber, out var pageSize);

IEnumerable<IAuditItem> auditItems = _auditRepository.GetPagedResultsByQuery(query, pageNumber, pageSize, out var totalRecords, orderDirection, auditTypeFilter, customFilter);
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Services/IAuditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
int skip,
int take,
Direction orderDirection = Direction.Descending,
DateTime? sinceDate = null,
DateTimeOffset? sinceDate = null,
AuditType[]? auditTypeFilter = null) => throw new NotImplementedException();

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Umbraco.Core/Services/ILogViewerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public interface ILogViewerService : IService
/// <param name="filterExpression">The query expression to filter on.</param>
/// <param name="logLevels">The log levels for which to retrieve the log messages.</param>
Task<Attempt<PagedModel<ILogEntry>?, LogViewerOperationStatus>> GetPagedLogsAsync(
DateTime? startDate,
DateTime? endDate,
DateTimeOffset? startDate,
DateTimeOffset? endDate,
int skip,
int take,
Direction orderDirection = Direction.Descending,
Expand Down Expand Up @@ -63,7 +63,7 @@ public interface ILogViewerService : IService
/// <param name="startDate">The start date for the date range.</param>
/// <param name="endDate">The end date for the date range.</param>
/// <returns>The value whether or not you are able to view the logs.</returns>
Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTime? startDate, DateTime? endDate);
Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate);

/// <summary>
/// Returns a number of the different log level entries.
Expand All @@ -72,7 +72,7 @@ public interface ILogViewerService : IService
/// </summary>
/// <param name="startDate">The start date for the date range.</param>
/// <param name="endDate">The end date for the date range.</param>
Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTime? startDate, DateTime? endDate);
Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate);

/// <summary>
/// Returns a paged model of all unique message templates and their counts.
Expand All @@ -83,7 +83,7 @@ public interface ILogViewerService : IService
/// <param name="endDate">The end date for the date range.</param>
/// <param name="skip">The amount of items to skip.</param>
/// <param name="take">The amount of items to take.</param>
Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTime? startDate, DateTime? endDate, int skip, int take);
Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTimeOffset? startDate, DateTimeOffset? endDate, int skip, int take);

/// <summary>
/// Get the log level values of the global minimum and the UmbracoFile one from the config file.
Expand Down
14 changes: 7 additions & 7 deletions src/Umbraco.Core/Services/LogViewerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public LogViewerService(

/// <inheritdoc/>
public async Task<Attempt<PagedModel<ILogEntry>?, LogViewerOperationStatus>> GetPagedLogsAsync(
DateTime? startDate,
DateTime? endDate,
DateTimeOffset? startDate,
DateTimeOffset? endDate,
int skip,
int take,
Direction orderDirection = Direction.Descending,
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task<PagedModel<ILogViewerQuery>> GetSavedLogQueriesAsync(int skip,
}

/// <inheritdoc/>
public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTime? startDate, DateTime? endDate)
public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
bool isAllowed = CanViewLogs(logTimePeriod);
Expand All @@ -123,7 +123,7 @@ public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(Date
}

/// <inheritdoc/>
public async Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTime? startDate, DateTime? endDate)
public async Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);

Expand All @@ -143,7 +143,7 @@ public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(Date
}

/// <inheritdoc/>
public async Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTime? startDate, DateTime? endDate, int skip, int take)
public async Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTimeOffset? startDate, DateTimeOffset? endDate, int skip, int take)
{
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);

Expand Down Expand Up @@ -183,7 +183,7 @@ public ReadOnlyDictionary<string, LogLevel> GetLogLevelsFromSinks()
/// <param name="startDate">The start date for the date range (can be null).</param>
/// <param name="endDate">The end date for the date range (can be null).</param>
/// <returns>The LogTimePeriod object used to filter logs.</returns>
private LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
private LogTimePeriod GetTimePeriod(DateTimeOffset? startDate, DateTimeOffset? endDate)
{
if (startDate is null || endDate is null)
{
Expand All @@ -199,7 +199,7 @@ private LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
}
}

return new LogTimePeriod(startDate.Value, endDate.Value);
return new LogTimePeriod(startDate.Value.LocalDateTime, endDate.Value.LocalDateTime);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ test.describe('Language tests', () => {
const isoCodeDanish = 'da-DK';

test.beforeEach(async ({umbracoApi}) => {
await umbracoApi.language.delete(isoCodeDanish);
await umbracoApi.language.ensureNameNotExists(languageNameDanish);
});

test.afterEach(async ({umbracoApi}) => {
await umbracoApi.language.delete(isoCodeDanish);
await umbracoApi.language.ensureNameNotExists(languageNameDanish);
});

test('can create a language', async ({umbracoApi}) => {
// Act
await umbracoApi.language.create(languageNameDanish, false, false, isoCodeDanish);

// Assert
expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();
});

test('can update a language', async ({umbracoApi}) => {
// Arrange
const wrongLanguageName = 'densk';

await umbracoApi.language.create(wrongLanguageName, false, false, isoCodeDanish);

const language = await umbracoApi.language.get(isoCodeDanish);

// Updates language
// Act
language.name = languageNameDanish;
await umbracoApi.language.update(isoCodeDanish, language);

Expand All @@ -39,10 +39,11 @@ test.describe('Language tests', () => {
});

test('can delete a language', async ({umbracoApi}) => {
// Arrange
await umbracoApi.language.create(languageNameDanish, false, false, isoCodeDanish);

expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();

//Act
await umbracoApi.language.delete(isoCodeDanish);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.describe('Stylesheet tests', () => {
expect(await umbracoApi.stylesheet.doesExist(stylesheetPath)).toBeTruthy();

// Act
await umbracoApi.stylesheet.delete(stylesheetPath);
await umbracoApi.stylesheet.delete(stylesheetName);

// Assert
expect(await umbracoApi.stylesheet.doesExist(stylesheetPath)).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {test} from '@umbraco/playwright-testhelpers';
import {expect} from "@playwright/test";

test.describe('Language tests', () => {
const languageName = 'Arabic';
const isoCode = 'ar';
const defaultLanguageName = 'English (United States)';
const defaultLanguageIsoCode = 'en-US';

test.beforeEach(async ({umbracoApi, umbracoUi}) => {
await umbracoUi.goToBackOffice();
await umbracoApi.language.ensureNameNotExists(languageName);
});

test.afterEach(async ({umbracoApi}) => {
await umbracoApi.language.ensureNameNotExists(languageName);
});

test('can add language @smoke', async ({umbracoApi, umbracoUi}) => {
// Arrange
await umbracoUi.language.goToSettingsTreeItem('Language');

// Act
await umbracoUi.language.clickCreateLink();
await umbracoUi.language.chooseLanguageByName(languageName);
await umbracoUi.language.clickSaveButton();

// Assert
expect(await umbracoApi.language.doesExist(isoCode)).toBeTruthy();
// Verify the created language displays in the list
await umbracoUi.language.clickLanguageRoot();
await umbracoUi.language.isLanguageNameVisible(languageName, true);
});

test('can update default language option @smoke', async ({umbracoApi, umbracoUi}) => {
// Arrange
await umbracoApi.language.create(languageName, false, false, isoCode);
expect(await umbracoApi.language.doesExist(isoCode)).toBeTruthy();
await umbracoUi.language.goToSettingsTreeItem('Language');

// Act
await umbracoUi.language.clickLanguageByName(languageName);
await umbracoUi.language.switchDefaultLanguageOption();
await umbracoUi.language.clickSaveButton();

// Assert
const languageData = await umbracoApi.language.get(isoCode);
expect(languageData.isDefault).toBe(true);

// Clean
// To delete this language, you need to change en-US to be default language
const defaultLanguageData = await umbracoApi.language.get(defaultLanguageIsoCode);
defaultLanguageData.isDefault = true;
await umbracoApi.language.update(defaultLanguageIsoCode, defaultLanguageData);
});

test('can update mandatory language option', async ({umbracoApi, umbracoUi}) => {
// Arrange
await umbracoApi.language.create(languageName, false, false, isoCode);
expect(await umbracoApi.language.doesExist(isoCode)).toBeTruthy();
await umbracoUi.language.goToSettingsTreeItem('Language');

// Act
await umbracoUi.language.clickLanguageByName(languageName);
await umbracoUi.language.switchMandatoryLanguageOption();
await umbracoUi.language.clickSaveButton();

// Assert
const languageData = await umbracoApi.language.get(isoCode);
expect(languageData.isMandatory).toBe(true);
});

test('can delete language @smoke', async ({umbracoApi, umbracoUi}) => {
// Arrange
await umbracoApi.language.create(languageName, false, false, isoCode);
expect(await umbracoApi.language.doesExist(isoCode)).toBeTruthy();
await umbracoUi.language.goToSettingsTreeItem('Language');

// Act
await umbracoUi.language.removeLanguageByName(languageName);

// Assert
await umbracoUi.language.isSuccessNotificationVisible();
expect(await umbracoApi.language.doesExist(isoCode)).toBeFalsy();
// TODO: uncomment this when the front-end is ready. Currently the deleted language is not disappeared after deleting.
//await umbracoUi.language.isLanguageNameVisible(languageName, false);
});

// TODO: Remove skip when the add fallback language function works
test.skip('can remove fallback language', async ({umbracoApi, umbracoUi}) => {
// Arrange
await umbracoApi.language.create(languageName, false, false, isoCode);
expect(await umbracoApi.language.doesExist(isoCode)).toBeTruthy();
await umbracoUi.language.goToSettingsTreeItem('Language');

// Act
await umbracoUi.language.clickLanguageByName(languageName);
await umbracoUi.language.removeFallbackLanguageByName(defaultLanguageName);
await umbracoUi.language.clickSaveButton();

// Act
const languageData = await umbracoApi.language.get(isoCode);
expect(languageData.fallbackIsoCode).toBeFalsy();
});

// TODO: Remove skip when the add fallback language function works
test.skip('can add fallback language', async ({umbracoApi, umbracoUi}) => {
// Arrange
await umbracoApi.language.create(languageName, false, false, isoCode, null);
expect(await umbracoApi.language.doesExist(isoCode)).toBeTruthy();
await umbracoUi.language.goToSettingsTreeItem('Language');

// Act
await umbracoUi.language.clickLanguageByName(languageName);
await umbracoUi.language.clickAddFallbackLanguageButton();
await umbracoUi.language.selectFallbackLanguageByName(defaultLanguageName);
await umbracoUi.language.clickSaveButton();

// Act
const languageData = await umbracoApi.language.get(isoCode);
expect(languageData.fallbackIsoCode).toBe(defaultLanguageIsoCode);
});
});

0 comments on commit 78d93a1

Please sign in to comment.