Skip to content

Commit

Permalink
Major version change 4.0.0
Browse files Browse the repository at this point in the history
Exceptions have removed
Code cleanup and format
Some methods re-written
Fixed some bugs/issues
  • Loading branch information
bberka committed Jun 26, 2023
1 parent a7dde97 commit a8462ce
Show file tree
Hide file tree
Showing 190 changed files with 1,551 additions and 2,334 deletions.
38 changes: 19 additions & 19 deletions src/EasMe.Authorization/EasMe.Authorization.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>C:\Users\kkass\source\build\easme</BaseOutputPath>
<Version>1.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<Title>EasMe.Authorization</Title>
<Authors>bberka</Authors>
<Description>AspNetCore authorization extender library. Easily manage and apply required roles for desired endpoints.</Description>
<PackageProjectUrl>https://github.com/bberka/EasMe/tree/master</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/bberka/EasMe/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryUrl>https://github.com/bberka/EasMe/tree/master</RepositoryUrl>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>C:\Users\kkass\source\build\easme</BaseOutputPath>
<Version>1.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<Title>EasMe.Authorization</Title>
<Authors>bberka</Authors>
<Description>AspNetCore authorization extender library. Easily manage and apply required roles for desired endpoints.</Description>
<PackageProjectUrl>https://github.com/bberka/EasMe/tree/master</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/bberka/EasMe/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryUrl>https://github.com/bberka/EasMe/tree/master</RepositoryUrl>

</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions src/EasMe.Authorization/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace EasMe.Authorization;

public enum HttpMethod {
public enum HttpMethod
{
GET,
POST,
PUT,
Expand All @@ -12,12 +13,14 @@ public enum HttpMethod {
TRACE
}

public enum AuthorizationType {
public enum AuthorizationType
{
HttpMethodAuthorization,
EndpointAuthorization
}

public static class EasMeClaimType {
public static class EasMeClaimType
{
/// <summary>
/// Claim Type for initializing User authorization in order to use <see cref="HttpMethodAuthorizationMiddleware" />.
/// <br />
Expand Down
9 changes: 5 additions & 4 deletions src/EasMe.Authorization/HasActionPermissionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;

namespace EasMe.Authorization;

Expand All @@ -22,20 +21,22 @@ namespace EasMe.Authorization;
/// <see cref="HttpContext.User" /> claims.
/// </example>
/// </summary>
public class HasActionPermissionAttribute : ActionFilterAttribute {
public class HasActionPermissionAttribute : ActionFilterAttribute
{
private readonly string _actionCode;

public HasActionPermissionAttribute(object actionCode) {
_actionCode = actionCode.ToString() ?? "";
if (string.IsNullOrEmpty(_actionCode))
throw new ArgumentNullException(nameof(_actionCode));
}

public HasActionPermissionAttribute(string actionCode) {
_actionCode = actionCode;
if (string.IsNullOrEmpty(_actionCode))
throw new ArgumentNullException(nameof(_actionCode));
}

public override void OnActionExecuting(ActionExecutingContext actionExecutingContext) {
if (actionExecutingContext.HttpContext.User.Identity is not { IsAuthenticated: true }) {
Trace.WriteLine("Not authenticated");
Expand All @@ -51,7 +52,7 @@ public override void OnActionExecuting(ActionExecutingContext actionExecutingCon

Trace.WriteLine(endPointPermissionString);
var permList = InternalHelper.SplitPermissions(endPointPermissionString);
Trace.WriteLine("Permission List: " + string.Join(",",permList));
Trace.WriteLine("Permission List: " + string.Join(",", permList));
if (permList.Length == 0) {
actionExecutingContext.Result = new ForbidResult();
return;
Expand Down
3 changes: 2 additions & 1 deletion src/EasMe.Authorization/HttpMethodAuthorizationMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace EasMe.Authorization;
/// <summary>
/// Is to authorize every user by <see cref="HttpMethod" /> permissions
/// </summary>
public class HttpMethodAuthorizationMiddleware {
public class HttpMethodAuthorizationMiddleware
{
private readonly RequestDelegate _next;

public HttpMethodAuthorizationMiddleware(RequestDelegate next) {
Expand Down
3 changes: 2 additions & 1 deletion src/EasMe.Authorization/InternalHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace EasMe.Authorization;

internal static class InternalHelper {
internal static class InternalHelper
{
internal static HttpMethod? GetHttpMethod(string permission) {
var parse = Enum.TryParse(typeof(HttpMethod), permission, out var obj);
if (!parse) return null;
Expand Down
4 changes: 4 additions & 0 deletions src/EasMe.Authorization/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# EasMe.Authorization

Permission Authorization helper for AsNetCore.Mvc.
Uses base HttpContext.User authentication and verifies permissions initialized by server

### Table of Contents

- Filters > HasPermissionAttribute
- Middlewares > HttpMethodAuthorizationMiddleware
- AuthorizationHelper
- Enums

### HasPermissionAttribute

1. Add "EasMeClaimType.EndPointPermissions" to User claims
2. Set value as list of permissions separeted by ","
3. Add HasPermission("PermissionName") to Controller or Endpoint Action

### HttpMethodAuthorizationMiddleware

1. Add "EasMeClaimType.HttpMethodPermissions" to User claims
2. Set value as list of permissions separeted by ","
3. Get permission values from "EasMe.Authorization.HttpMethod" enum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4fafd1b16d689fcdf2c18739c1f9c50f9f85f4fa
aeedc4284f04e07a61c4999a2ba39b935d430ab2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 6 additions & 4 deletions src/EasMe.Box/Box.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Windows.Forms;

namespace EasMe.MessageBox {
public static class Box {
namespace EasMe.MessageBox
{
public static class Box
{
public static bool Confirm(string Message) //Shows a confirmation box and returns the result taken from user
{
if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show(Message, "Confirmation",
MessageBoxButtons.YesNo, MessageBoxIcon.Question))
MessageBoxButtons.YesNo, MessageBoxIcon.Question))
return true;
return false;
}
Expand All @@ -23,7 +25,7 @@ public static void Warn(string Message) //Shows a warning message box with only
public static void Info(string Message) //Shows an information message box with only OK buttong
{
System.Windows.Forms.MessageBox.Show(Message, "Information", MessageBoxButtons.OK,
MessageBoxIcon.Information);
MessageBoxIcon.Information);
}

public static void Error(string Message) //Shows an Error message box with only OK buttong
Expand Down
86 changes: 43 additions & 43 deletions src/EasMe.Box/EasMe.Box.csproj
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A34014DE-E353-44E7-874F-CFD7E3F16137}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EasMe.MessageBox</RootNamespace>
<AssemblyName>EasMe.MessageBox</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Box.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A34014DE-E353-44E7-874F-CFD7E3F16137}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EasMe.MessageBox</RootNamespace>
<AssemblyName>EasMe.MessageBox</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Windows.Forms"/>
</ItemGroup>
<ItemGroup>
<Compile Include="Box.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup>
<ItemGroup>
<None Include="README.md"/>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
</Project>
6 changes: 4 additions & 2 deletions src/EasMe.EntityFrameworkCore/BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace EasMe.EntityFrameworkCore;

public abstract class BaseEntity : IBaseEntity {
public abstract class BaseEntity : IBaseEntity
{
protected BaseEntity(Guid guid) {
Id = guid;
}
Expand All @@ -12,7 +13,8 @@ protected BaseEntity() {

public DateTime RegisterDate { get; set; } = DateTime.Now;

[Key] public Guid Id { get; set; }
[Key]
public Guid Id { get; set; }

public bool Equals(BaseEntity? other) {
if (other is null) return false;
Expand Down
36 changes: 18 additions & 18 deletions src/EasMe.EntityFrameworkCore/EasMe.EntityFrameworkCore.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>C:\Users\kkass\source\build\easme</BaseOutputPath>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>EasMe.EntityFrameworkCore</Title>
<Description>EntityFrameworkCore extender library with built in repository pattern interfaces and more.</Description>
<PackageProjectUrl>https://github.com/bberka/EasMe/tree/master</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/bberka/EasMe/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryUrl>https://github.com/bberka/EasMe/tree/master</RepositoryUrl>
<Authors>bberka</Authors>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>C:\Users\kkass\source\build\easme</BaseOutputPath>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>EasMe.EntityFrameworkCore</Title>
<Description>EntityFrameworkCore extender library with built in repository pattern interfaces and more.</Description>
<PackageProjectUrl>https://github.com/bberka/EasMe/tree/master</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/bberka/EasMe/blob/master/LICENSE.txt</PackageLicenseUrl>
<RepositoryUrl>https://github.com/bberka/EasMe/tree/master</RepositoryUrl>
<Authors>bberka</Authors>


</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5"/>
</ItemGroup>

</Project>
11 changes: 6 additions & 5 deletions src/EasMe.EntityFrameworkCore/EntityRepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace EasMe.EntityFrameworkCore;
/// <typeparam name="TContext"></typeparam>
public class EntityRepositoryBase<TEntity, TContext> : IEntityRepository<TEntity>
where TEntity : class, IEntity, new()
where TContext : DbContext, new() {
where TContext : DbContext, new()
{
private readonly TContext _dbContext;
private readonly DbSet<TEntity> _dbSet;

Expand All @@ -21,14 +22,14 @@ public EntityRepositoryBase(TContext dbContext) {

public IQueryable<TEntity> Get(Expression<Func<TEntity, bool>>? filter = null) {
return filter == null
? _dbSet
: _dbSet.Where(filter);
? _dbSet
: _dbSet.Where(filter);
}

public List<TEntity> GetList(Expression<Func<TEntity, bool>>? filter = null) {
return filter == null
? _dbSet.ToList()
: _dbSet.Where(filter).ToList();
? _dbSet.ToList()
: _dbSet.Where(filter).ToList();
}

public TEntity? GetFirstOrDefault(Expression<Func<TEntity, bool>> filter) {
Expand Down
Loading

0 comments on commit a8462ce

Please sign in to comment.