Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Adapt changes from 8.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Jul 27, 2024
1 parent 8362132 commit a2080e3
Show file tree
Hide file tree
Showing 36 changed files with 909 additions and 816 deletions.
2 changes: 1 addition & 1 deletion Serenity
Submodule Serenity updated 331 files
5 changes: 3 additions & 2 deletions src/Serene.Web/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"isRoot": true,
"tools": {
"sergen": {
"version": "8.4.8",
"version": "8.6.0",
"commands": [
"sergen"
]
],
"rollForward": false
}
}
}
5 changes: 3 additions & 2 deletions src/Serene.Web/Initialization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IHttpContextItemsAccessor, HttpContextItemsAccessor>();
services.AddSingleton<INavigationModelFactory, AppServices.NavigationModelFactory>();
services.AddSingleton<IPermissionService, AppServices.PermissionService>();
services.AddSingleton<IRolePermissionService, AppServices.RolePermissionService>();
services.AddSingleton<IPermissionService, AppServices.PermissionService>();
services.AddSingleton<IPermissionKeyLister, AppServices.PermissionKeyLister>();
services.AddSingleton<IRolePermissionService, AppServices.RolePermissionService>();
services.AddSingleton<IUploadAVScanner, ClamAVUploadScanner>();
services.AddSingleton<IUserPasswordValidator, AppServices.UserPasswordValidator>();
services.AddSingleton<IUserAccessor, AppServices.UserAccessor>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Decorators, EntityGrid, Fluent, GridUtils, LookupEditor, LookupEditorOptions, ToolButton, Widget } from "@serenity-is/corelib";
import { confirm, isEmptyOrNull, isTrimmedEmpty, notifySuccess, outerHtml, localText, trimToEmpty, trimToNull } from "@serenity-is/corelib";
import { Column } from "@serenity-is/sleekgrid";
import { TranslationItem, TranslationService } from "../";
import { confirmDialog, Decorators, EntityGrid, Fluent, GridUtils, isEmptyOrNull, isTrimmedEmpty, localText, LookupEditor, LookupEditorOptions, notifySuccess, outerHtml, stripDiacritics, ToolButton, trimToEmpty, trimToNull, Widget } from "@serenity-is/corelib";
import { Column } from "@serenity-is/sleekgrid";
import { TranslationItem, TranslationService } from "../";

@Decorators.registerClass()
export class TranslationGrid extends EntityGrid<TranslationItem, any> {
Expand Down Expand Up @@ -55,7 +54,7 @@ export class TranslationGrid extends EntityGrid<TranslationItem, any> {
return;
}

confirm(localText('Db.Administration.Translation.OverrideConfirmation'), done);
confirmDialog(localText('Db.Administration.Translation.OverrideConfirmation'), done);
return;
}

Expand All @@ -74,7 +73,7 @@ export class TranslationGrid extends EntityGrid<TranslationItem, any> {
return;
}

confirm(localText('Db.Administration.Translation.OverrideConfirmation'), done);
confirmDialog(localText('Db.Administration.Translation.OverrideConfirmation'), done);
return;
}
}
Expand Down Expand Up @@ -210,7 +209,7 @@ export class TranslationGrid extends EntityGrid<TranslationItem, any> {
return true;
}

var sd = Select2.util.stripDiacritics;
var sd = stripDiacritics;
var searching = sd(this.searchText).toLowerCase();

function match(str: string) {
Expand Down

This file was deleted.

9 changes: 4 additions & 5 deletions src/Serene.Web/Modules/Administration/User/UserDataScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public class UserDataScript : DataScript<ScriptUserDefinition>
{
private readonly ITwoLevelCache cache;
private readonly IPermissionService permissions;
private readonly ITypeSource typeSource;
private readonly IPermissionKeyLister permissionKeyLister;
private readonly IUserAccessor userAccessor;
private readonly IUserRetrieveService userRetriever;

public UserDataScript(ITwoLevelCache cache, IPermissionService permissions,
ITypeSource typeSource, IUserAccessor userAccessor, IUserRetrieveService userRetriever)
IPermissionKeyLister permissionKeyLister, IUserAccessor userAccessor, IUserRetrieveService userRetriever)
{
this.cache = cache ?? throw new ArgumentNullException(nameof(cache));
this.permissions = permissions ?? throw new ArgumentNullException(nameof(permissions));
this.typeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource));
this.permissionKeyLister = permissionKeyLister ?? throw new ArgumentNullException(nameof(permissionKeyLister));
this.userAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor));
this.userRetriever = userRetriever ?? throw new ArgumentNullException(nameof(userRetriever));
}
Expand All @@ -46,8 +46,7 @@ protected override ScriptUserDefinition GetData()
var permissionsUsedFromScript = cache.GetLocalStoreOnly("PermissionsUsedFromScript",
TimeSpan.Zero, RoleRow.Fields.GenerationKey, () =>
{
return UserPermissionRepository.ListPermissionKeys(
cache, typeSource)
return permissionKeyLister.ListPermissionKeys(includeRoles: false)
.Where(permissionKey =>
{
// this sends permission information for all permission keys to client side.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataGrid, Decorators, Dictionary, Fluent, GridUtils, Grouping, IGetEditValue, ISetEditValue, SlickFormatting, SlickTreeHelper, ToolButton, WidgetProps, any, count, getRemoteData, htmlEncode, localText, toGrouping, trimToNull, tryGetText, turkishLocaleCompare } from "@serenity-is/corelib";
import { DataGrid, Decorators, Dictionary, Fluent, GridUtils, Grouping, IGetEditValue, ISetEditValue, SlickFormatting, SlickTreeHelper, ToolButton, WidgetProps, any, count, getRemoteData, htmlEncode, localText, stripDiacritics, toGrouping, trimToNull, tryGetText, turkishLocaleCompare } from "@serenity-is/corelib";
import { Column } from "@serenity-is/sleekgrid";
import { UserPermissionRow } from "../";

Expand Down Expand Up @@ -157,8 +157,8 @@ export class PermissionCheckEditor extends DataGrid<PermissionCheckItem, Permiss
}

private matchContains(item: PermissionCheckItem): boolean {
return Select2.util.stripDiacritics(item.Title || '').toLowerCase().indexOf(this.searchText) >= 0 ||
Select2.util.stripDiacritics(item.Key || '').toLowerCase().indexOf(this.searchText) >= 0;
return stripDiacritics(item.Title || '').toLowerCase().indexOf(this.searchText) >= 0 ||
stripDiacritics(item.Key || '').toLowerCase().indexOf(this.searchText) >= 0;
}

private getDescendants(item: PermissionCheckItem, excludeGroups: boolean): PermissionCheckItem[] {
Expand Down Expand Up @@ -240,7 +240,7 @@ export class PermissionCheckEditor extends DataGrid<PermissionCheckItem, Permiss
protected createToolbarExtensions(): void {
super.createToolbarExtensions();
GridUtils.addQuickSearchInputCustom(this.toolbar.element, (_, text) => {
this.searchText = Select2.util.stripDiacritics(trimToNull(text) || '').toLowerCase();
this.searchText = stripDiacritics(trimToNull(text) || '').toLowerCase();
this.view.setItems(this.view.getItems(), true);
});
}
Expand All @@ -256,7 +256,7 @@ export class PermissionCheckEditor extends DataGrid<PermissionCheckItem, Permiss
}

if (s.charAt(s.length - 1) == ':') {
s = s.substr(0, s.length - 1);
s = s.substring(0, s.length - 1);
if (s.length === 0) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ namespace Serene.Administration;
using Serenity.Abstractions;
using Serenity.ComponentModel;
using Serenity.Web;
using Serene.Administration.Repositories;
using System;
using System.Collections.Generic;

[DataScript("Administration.PermissionKeys", Permission = PermissionKeys.Security)]
public class PermissionKeysDataScript : DataScript<IEnumerable<string>>
{
private readonly ITwoLevelCache cache;
private readonly ITypeSource typeSource;

public PermissionKeysDataScript(ITwoLevelCache cache, ITypeSource typeSource)
private readonly IPermissionKeyLister permissionKeyLister;

public PermissionKeysDataScript(IPermissionKeyLister permissionKeyLister)
{
GroupKey = RoleRow.Fields.GenerationKey;
this.cache = cache ?? throw new ArgumentNullException(nameof(cache));
this.typeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource));
this.permissionKeyLister = permissionKeyLister ?? throw new ArgumentNullException(nameof(permissionKeyLister));
}

protected override IEnumerable<string> GetData()
{
return UserPermissionRepository.ListPermissionKeys(cache, typeSource);
return permissionKeyLister.ListPermissionKeys(includeRoles: false);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MyRepository = Serene.Administration.Repositories.UserPermissionRepository;
using MyRepository = Serene.Administration.Repositories.UserPermissionRepository;
using MyRow = Serene.Administration.UserPermissionRow;

namespace Serene.Administration.Endpoints;
Expand All @@ -24,11 +24,11 @@ public ListResponse<string> ListRolePermissions(IDbConnection connection, UserPe
}

public ListResponse<string> ListPermissionKeys(
[FromServices] ITypeSource typeSource)
[FromServices] IPermissionKeyLister permissionKeyLister)
{
return new ListResponse<string>
{
Entities = MyRepository.ListPermissionKeys(Cache, typeSource).ToList()
Entities = permissionKeyLister.ListPermissionKeys(includeRoles: false).ToList()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,100 +128,4 @@ public ListResponse<string> ListRolePermissions(IDbConnection connection, UserPe
Entities = connection.Query<string>(query).ToList()
};
}

private static readonly string[] emptyPermissions = Array.Empty<string>();
private static readonly char[] splitChar = new char[] { '|', '&' };

private static string[] SplitPermissions(string permission)
{
if (string.IsNullOrEmpty(permission))
return emptyPermissions;

return permission.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
}

private static void ProcessAttributes<TAttr>(HashSet<string> hash,
MemberInfo member, Func<TAttr, string> getPermission)
where TAttr : Attribute
{
try
{
foreach (var attr in member.GetCustomAttributes<TAttr>(false))
{
var permission = getPermission(attr);
hash.AddRange(SplitPermissions(permission));
}
}
catch
{
// GetCustomAttributes might fail before .NET 4.6
}
}

private static void ProcessAttributes<TAttr>(HashSet<string> hash,
Type member, Func<TAttr, string> getPermission)
where TAttr : Attribute
{
try
{
foreach (var attr in member.GetCustomAttributes<TAttr>(false))
{
var permission = getPermission(attr);
hash.AddRange(SplitPermissions(permission));
}
}
catch
{
// GetCustomAttributes might fail before .NET 4.6
}
}

public static IEnumerable<string> ListPermissionKeys(ITwoLevelCache cache,
ITypeSource typeSource, bool includeRoles = false)
{
if (typeSource is null)
throw new ArgumentNullException(nameof(typeSource));

return cache.GetLocalStoreOnly("Administration:PermissionKeys:" +
(includeRoles ? "IR" : "XR"), TimeSpan.Zero, RoleRow.Fields.GenerationKey, () =>
{
var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

result.AddRange(NestedPermissionKeyRegistration.AddNestedPermissions(registry: null, typeSource));

foreach (var attr in typeSource.GetAssemblyAttributes<PermissionAttributeBase>())
if (!attr.Permission.IsEmptyOrNull())
result.AddRange(SplitPermissions(attr.Permission));

foreach (var type in typeSource.GetTypes())
{
ProcessAttributes<PageAuthorizeAttribute>(result, type, x => x.Permission);
ProcessAttributes<PermissionAttributeBase>(result, type, x => x.Permission);
ProcessAttributes<ServiceAuthorizeAttribute>(result, type, x => x.Permission);

foreach (var member in type.GetMethods(BindingFlags.Instance | BindingFlags.Public))
{
ProcessAttributes<PageAuthorizeAttribute>(result, member, x => x.Permission);
ProcessAttributes<PermissionAttributeBase>(result, member, x => x.Permission);
ProcessAttributes<ServiceAuthorizeAttribute>(result, member, x => x.Permission);
}

foreach (var member in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
if (member.GetIndexParameters().Length == 0)
ProcessAttributes<PermissionAttributeBase>(result, member, x => x.Permission);
}

result.Remove("ImpersonateAs");
result.Remove("*");
result.Remove("?");

foreach (var perm in result.Where(x =>
x.StartsWith("Role:", StringComparison.OrdinalIgnoreCase)).ToList())
{
result.Remove(perm);
}

return result;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CheckTreeEditor, CheckTreeItem, Decorators, GridUtils } from "@serenity-is/corelib";
import { CheckTreeEditor, CheckTreeItem, Decorators, GridUtils, stripDiacritics } from "@serenity-is/corelib";
import { isEmptyOrNull } from "@serenity-is/corelib";
import { RoleRow } from "../";

Expand All @@ -15,7 +15,7 @@ export class RoleCheckEditor extends CheckTreeEditor<CheckTreeItem<any>, any> {
super.createToolbarExtensions();

GridUtils.addQuickSearchInputCustom(this.toolbar.element, (field, text) => {
this.searchText = Select2.util.stripDiacritics(text || '').toUpperCase();
this.searchText = stripDiacritics(text || '').toUpperCase();
this.view.setItems(this.view.getItems(), true);
});
}
Expand All @@ -34,7 +34,7 @@ export class RoleCheckEditor extends CheckTreeEditor<CheckTreeItem<any>, any> {
protected onViewFilter(item) {
return super.onViewFilter(item) &&
(isEmptyOrNull(this.searchText) ||
Select2.util.stripDiacritics(item.text || '')
stripDiacritics(item.text || '')
.toUpperCase().indexOf(this.searchText) >= 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Serene;

public interface IDataMigrations
{
void Initialize();
namespace Serene;

public interface IDataMigrations
{
void Initialize();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


namespace Serene;

public interface IDirectoryService
Expand Down
Loading

0 comments on commit a2080e3

Please sign in to comment.