employees
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
namespace LaaProduction.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
|
||||
public class AccountManager : IAccountManager
|
||||
{
|
||||
private static IIdentity anonymous
|
||||
=> new ClaimsIdentity(
|
||||
claims: Array.Empty<Claim>(),
|
||||
authenticationType: string.Empty,
|
||||
nameType: string.Empty,
|
||||
roleType: string.Empty);
|
||||
|
||||
private readonly IEmployeesRepository employeesRepository;
|
||||
private readonly ISoftwareRepository softwareRepository;
|
||||
|
||||
public AccountManager()
|
||||
{
|
||||
this.employeesRepository = ServiceProvider.GetService<IEmployeesRepository>();
|
||||
this.softwareRepository = ServiceProvider.GetService<ISoftwareRepository>();
|
||||
}
|
||||
|
||||
public string GetAuthToken(string username, string password, string software)
|
||||
{
|
||||
var userId = this.employeesRepository.EmployeeId(username, password);
|
||||
var token = default(string);
|
||||
|
||||
if (userId > 0)
|
||||
{
|
||||
var appId = this.softwareRepository.AppId(software);
|
||||
|
||||
if (appId > 0)
|
||||
{
|
||||
this.employeesRepository.CreateToken(appId, userId);
|
||||
|
||||
token = this.employeesRepository.GetToken(appId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
public IPrincipal GetClaimsPrincipal(string token)
|
||||
{
|
||||
var claimsIdentity = anonymous;
|
||||
|
||||
if (this.employeesRepository.TokenExists(token))
|
||||
{
|
||||
var employee = this.employeesRepository.GetEmployee(token);
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim(nameof(employee.EmployeeId), employee.EmployeeId.ToString()),
|
||||
new Claim(nameof(employee.FullName), employee.FullName),
|
||||
new Claim(nameof(employee.Username), employee.Username),
|
||||
new Claim(ClaimTypes.NameIdentifier, token),
|
||||
};
|
||||
|
||||
var userRoles = this.employeesRepository
|
||||
.GetUserRoles(token)
|
||||
.Intersect(typeof(UsersRoles));
|
||||
|
||||
foreach (var role in userRoles)
|
||||
{
|
||||
claims.Add(new Claim(nameof(UsersRoles), role));
|
||||
}
|
||||
|
||||
var functions = this.softwareRepository
|
||||
.GetSoftwareFunctions(token)
|
||||
.Intersect(typeof(SoftwareFunctions));
|
||||
|
||||
foreach (var func in functions)
|
||||
{
|
||||
claims.Add(new Claim(nameof(SoftwareFunctions), func));
|
||||
}
|
||||
|
||||
claimsIdentity = new ClaimsIdentity(
|
||||
claims: claims,
|
||||
authenticationType: nameof(ClaimsIdentity),
|
||||
nameType: nameof(employee.EmployeeId),
|
||||
roleType: nameof(UsersRoles));
|
||||
}
|
||||
|
||||
return new ClaimsPrincipal(claimsIdentity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace LaaProduction.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
using LaaProduction.Personalization.Models;
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class EmployeesManager : IEmployeesManager
|
||||
{
|
||||
private readonly IEmployeesRepository employeesRepository;
|
||||
private readonly IRolesRepository rolesRepository;
|
||||
|
||||
public EmployeesManager()
|
||||
{
|
||||
this.employeesRepository = ServiceProvider.GetService<IEmployeesRepository>();
|
||||
this.rolesRepository = ServiceProvider.GetService<IRolesRepository>();
|
||||
}
|
||||
|
||||
public object GetEmployee(short employeeId)
|
||||
=> this.employeesRepository.Find(employeeId)
|
||||
?? new object { };
|
||||
|
||||
public IEnumerable<object> GetEmployees()
|
||||
=> this.employeesRepository.All()
|
||||
?? Array.Empty<Employee>();
|
||||
|
||||
public IEnumerable<string> GetRoles()
|
||||
=> this.rolesRepository.All()
|
||||
?? Array.Empty<string>();
|
||||
|
||||
public IDictionary<string, bool> GetRoles(short employeeId)
|
||||
=> this.rolesRepository
|
||||
.All(employeeId)
|
||||
.ToDictionary(x => x.Key, x => x.Value)
|
||||
?? new Dictionary<string, bool>();
|
||||
|
||||
public void UpdateEmployeeRoles(short employeeId, IEnumerable<string> roles)
|
||||
{
|
||||
this.rolesRepository.Delete(employeeId);
|
||||
this.rolesRepository.Insert(employeeId, roles);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace LaaProduction.Personalization.Interfaces
|
||||
{
|
||||
using System.Security.Principal;
|
||||
|
||||
public interface IAccountManager
|
||||
{
|
||||
string GetAuthToken(string username, string password, string software);
|
||||
|
||||
IPrincipal GetClaimsPrincipal(string token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace LaaProduction.Personalization.Interfaces
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface IEmployeesManager
|
||||
{
|
||||
object GetEmployee(short employeeId);
|
||||
|
||||
IEnumerable<object> GetEmployees();
|
||||
|
||||
IDictionary<string, bool> GetRoles(short employeeId);
|
||||
|
||||
IEnumerable<string> GetRoles();
|
||||
|
||||
void UpdateEmployeeRoles(short employeeId, IEnumerable<string> roles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?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>{4C17FD42-7002-431A-8D6E-C57DD7D7C2D2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>LaaProduction.Personalization</RootNamespace>
|
||||
<AssemblyName>LaaProduction.Personalization</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</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\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="LaaProductionSQL, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\LaaProductionSQL.1.0.0\lib\netstandard2.0\LaaProductionSQL.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.7.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.SqlClient, Version=4.6.1.5, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Data.SqlClient.4.8.5\lib\net461\System.Data.SqlClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AccountManager.cs" />
|
||||
<Compile Include="EmployeesManager.cs" />
|
||||
<Compile Include="Interfaces\IEmployeesManager.cs" />
|
||||
<Compile Include="PersonalizationExtensions.cs" />
|
||||
<Compile Include="Interfaces\IAccountManager.cs" />
|
||||
<Compile Include="Models\Employee.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Repositories\EmployeesRepository.cs" />
|
||||
<Compile Include="Repositories\Interfaces\IEmployeesRepository.cs" />
|
||||
<Compile Include="Repositories\Interfaces\IRolesRepository.cs" />
|
||||
<Compile Include="Repositories\Interfaces\ISoftwareRepository.cs" />
|
||||
<Compile Include="Repositories\RolesRepository.cs" />
|
||||
<Compile Include="Repositories\SoftwareRepository.cs" />
|
||||
<Compile Include="ServiceProvider.cs" />
|
||||
<Compile Include="SoftwareFunctions.cs" />
|
||||
<Compile Include="UsersRoles.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace LaaProduction.Personalization.Models
|
||||
{
|
||||
internal class Employee
|
||||
{
|
||||
public short EmployeeId { get; set; }
|
||||
|
||||
public string FullName { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public int RolesCount { get; set; }
|
||||
|
||||
public int FunctionsCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace LaaProduction.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Interfaces;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public static class PersonalizationExtensions
|
||||
{
|
||||
public static IServiceCollection AddAdministration(this IServiceCollection services, string sqlConnectionString)
|
||||
{
|
||||
ServiceProvider.RegisterServices(sqlConnectionString);
|
||||
|
||||
return services
|
||||
.AddScoped<IAccountManager, AccountManager>()
|
||||
.AddScoped<IEmployeesManager, EmployeesManager>();
|
||||
}
|
||||
|
||||
internal static IEnumerable<string> Intersect(this IEnumerable<string> source, Type enumType)
|
||||
=> Enum.GetNames(enumType).Intersect(source);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("LaaProduction.Administration")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("LaaProduction.Administration")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("4c17fd42-7002-431a-8d6e-c57dd7d7c2d2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,10 @@
|
||||
Database table dependencies
|
||||
---
|
||||
[Auftrag].[dbo].[Mitarbeiter]
|
||||
[Auftrag].[dbo].[MitarbeiterRechte]
|
||||
[Auftrag].[dbo].[MitarbeiterTokens]
|
||||
[Auftrag].[dbo].[MitarbeiterTokens]
|
||||
[Auftrag].[dbo].[SoftwareFunctions]
|
||||
[Auftrag].[dbo].[SoftwareFunctionsLog]
|
||||
[Auftrag].[dbo].[UsersFunctions]
|
||||
[Auftrag].[dbo].[VersionSoftwareAccess]
|
||||
@@ -0,0 +1,155 @@
|
||||
namespace LaaProduction.Personalization.Repositories
|
||||
{
|
||||
using LaaProduction.Personalization.Models;
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
|
||||
using LaaProductionSQL.Interfaces;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class EmployeesRepository : IEmployeesRepository
|
||||
{
|
||||
private readonly ISQLConnection sqlConnection;
|
||||
|
||||
public EmployeesRepository(ISQLConnection sqlConnection)
|
||||
=> this.sqlConnection = sqlConnection;
|
||||
|
||||
public IEnumerable<Employee> All()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT
|
||||
[E].[EmployeeId] AS [EmployeeId]
|
||||
, [E].[FullName] AS [FullName]
|
||||
, [E].[Username] AS [Username]
|
||||
, [E].[RolesCount] AS [RolesCount]
|
||||
, COUNT([UF].[SoftwareFunctionId])
|
||||
OVER (PARTITION BY [E].[EmployeeId]) AS [FunctionsCount]
|
||||
FROM (SELECT DISTINCT
|
||||
[M].[MitarbeiterNr] AS [EmployeeId]
|
||||
, [M].[Vorname] + ' ' + [M].[Name] AS [FullName]
|
||||
, [M].[Benutzername] AS [Username]
|
||||
, COUNT([MR].[Recht])
|
||||
OVER (PARTITION BY [M].[MitarbeiterNr]) AS [RolesCount]
|
||||
FROM [Mitarbeiter] AS [M]
|
||||
LEFT JOIN [MitarbeiterRechte] AS [MR]
|
||||
ON [MR].[MitarbeiterNr] = [M].[MitarbeiterNr])
|
||||
AS [E]
|
||||
LEFT JOIN [UsersFunctions] AS [UF]
|
||||
ON [UF].[UserId] = [E].[EmployeeId]
|
||||
ORDER BY [E].[FullName]")
|
||||
.ExecuteReader(x => new Employee
|
||||
{
|
||||
EmployeeId = x.GetSmallint(),
|
||||
FullName = x.GetString(),
|
||||
Username = x.GetString(),
|
||||
RolesCount = x.GetInt(),
|
||||
FunctionsCount = x.GetInt()
|
||||
});
|
||||
|
||||
public void CreateToken(short appId, short userId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
INSERT INTO [MitarbeiterTokens] (
|
||||
[AppId]
|
||||
, [UserId])
|
||||
VALUES (@{nameof(appId)}
|
||||
, @{nameof(userId)})")
|
||||
.SetParameter(nameof(appId), appId)
|
||||
.SetParameter(nameof(userId), userId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public short EmployeeId(string username, string password)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [MitarbeiterNr]
|
||||
FROM [Mitarbeiter]
|
||||
WHERE [Benutzername] = @{nameof(username)}
|
||||
AND [PasswordHash] = @{nameof(password)}")
|
||||
.SetParameter(nameof(username), username)
|
||||
.SetParameter(nameof(password), password)
|
||||
.FirstOrDefault(x => x.GetSmallint());
|
||||
|
||||
public Employee Find(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT
|
||||
[E].[EmployeeId] AS [EmployeeId]
|
||||
, [E].[FullName] AS [FullName]
|
||||
, [E].[Username] AS [Username]
|
||||
, [E].[RolesCount] AS [RolesCount]
|
||||
, COUNT([UF].[SoftwareFunctionId])
|
||||
OVER (PARTITION BY [E].[EmployeeId]) AS [FunctionsCount]
|
||||
FROM (SELECT DISTINCT
|
||||
[M].[MitarbeiterNr] AS [EmployeeId]
|
||||
, [M].[Vorname] + ' ' + [M].[Name] AS [FullName]
|
||||
, [M].[Benutzername] AS [Username]
|
||||
, COUNT([MR].[Recht])
|
||||
OVER (PARTITION BY [M].[MitarbeiterNr]) AS [RolesCount]
|
||||
FROM [Mitarbeiter] AS [M]
|
||||
LEFT JOIN [MitarbeiterRechte] AS [MR]
|
||||
ON [MR].[MitarbeiterNr] = [M].[MitarbeiterNr]
|
||||
WHERE [M].[MitarbeiterNr] = @{nameof(employeeId)})
|
||||
AS [E]
|
||||
LEFT JOIN [UsersFunctions] AS [UF]
|
||||
ON [UF].[UserId] = [E].[EmployeeId]
|
||||
ORDER BY [E].[FullName]")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.FirstOrDefault(x => new Employee
|
||||
{
|
||||
EmployeeId = x.GetSmallint(),
|
||||
FullName = x.GetString(),
|
||||
Username = x.GetString(),
|
||||
RolesCount = x.GetInt(),
|
||||
FunctionsCount = x.GetInt()
|
||||
});
|
||||
|
||||
public Employee GetEmployee(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [M].[MitarbeiterNr]
|
||||
, [M].[Vorname] + ' ' + [M].[Name]
|
||||
, [M].[Benutzername]
|
||||
FROM [MitarbeiterTokens] AS [MT]
|
||||
JOIN [Mitarbeiter] AS [M]
|
||||
ON [M].[MitarbeiterNr] = [MT].[UserId]
|
||||
WHERE [MT].[Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.FirstOrDefault(x => new Employee
|
||||
{
|
||||
EmployeeId = x.GetSmallint(),
|
||||
FullName = x.GetString(),
|
||||
Username = x.GetString()
|
||||
});
|
||||
|
||||
public string GetToken(short appId, short userId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [Token]
|
||||
FROM [MitarbeiterTokens]
|
||||
WHERE [AppId] = @{nameof(appId)}
|
||||
AND [UserId] = @{nameof(userId)}")
|
||||
.SetParameter(nameof(appId), appId)
|
||||
.SetParameter(nameof(userId), userId)
|
||||
.FirstOrDefault(x => x.GetString());
|
||||
|
||||
public IEnumerable<string> GetUserRoles(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [MR].[Recht]
|
||||
FROM [MitarbeiterTokens] AS [MT]
|
||||
JOIN [MitarbeiterRechte] AS [MR]
|
||||
ON [MR].[MitarbeiterNr] = [MT].[UserId]
|
||||
WHERE [MT].[Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public bool TokenExists(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT COUNT(1)
|
||||
FROM [MitarbeiterTokens]
|
||||
WHERE [Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.FirstOrDefault(x => x.GetInt() > 0);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
namespace LaaProduction.Personalization.Repositories.Interfaces
|
||||
{
|
||||
using LaaProduction.Personalization.Models;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal interface IEmployeesRepository
|
||||
{
|
||||
IEnumerable<Employee> All();
|
||||
|
||||
void CreateToken(short appId, short userId);
|
||||
|
||||
short EmployeeId(string username, string password);
|
||||
|
||||
Employee Find(short employeeId);
|
||||
|
||||
Employee GetEmployee(string token);
|
||||
|
||||
string GetToken(short appId, short userId);
|
||||
|
||||
IEnumerable<string> GetUserRoles(string token);
|
||||
|
||||
bool TokenExists(string token);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
namespace LaaProduction.Personalization.Repositories.Interfaces
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface IRolesRepository
|
||||
{
|
||||
IEnumerable<string> All();
|
||||
|
||||
IEnumerable<KeyValuePair<string, bool>> All(short employeeId);
|
||||
|
||||
void Delete(short employeeId);
|
||||
|
||||
void Insert(short employeeId, IEnumerable<string> roles);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
namespace LaaProduction.Personalization.Repositories.Interfaces
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal interface ISoftwareRepository
|
||||
{
|
||||
short AppId(string software);
|
||||
|
||||
IEnumerable<string> GetSoftwareFunctions(string token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace LaaProduction.Personalization.Repositories
|
||||
{
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
using LaaProductionSQL.Interfaces;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
public class RolesRepository : IRolesRepository
|
||||
{
|
||||
private readonly ISQLConnection sqlConnection;
|
||||
|
||||
public RolesRepository(ISQLConnection sqlConnection)
|
||||
=> this.sqlConnection = sqlConnection;
|
||||
|
||||
public IEnumerable<string> All()
|
||||
=> this.sqlConnection
|
||||
.CreateCommand(@"
|
||||
SELECT DISTINCT [Recht]
|
||||
FROM [MitarbeiterRechte]")
|
||||
.ExecuteReader(x => x.GetString());
|
||||
|
||||
public IEnumerable<KeyValuePair<string, bool>> All(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT DISTINCT
|
||||
[AllRoles].[Recht]
|
||||
, CAST(CASE WHEN [UsrRoles].[MitarbeiterNr] IS NULL THEN 0 ELSE 1 END AS BIT)
|
||||
FROM [MitarbeiterRechte] AS [AllRoles]
|
||||
LEFT JOIN [MitarbeiterRechte] AS [UsrRoles]
|
||||
ON [UsrRoles].[Recht] = [AllRoles].[Recht]
|
||||
AND [UsrRoles].[MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteReader(x => new KeyValuePair<string, bool>(x.GetString(), x.GetBool()));
|
||||
|
||||
public void Delete(short employeeId)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
DELETE FROM [MitarbeiterRechte]
|
||||
WHERE [MitarbeiterNr] = @{nameof(employeeId)}")
|
||||
.SetParameter(nameof(employeeId), employeeId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
public void Insert(short employeeId, IEnumerable<string> roles)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
INSERT INTO [MitarbeiterRechte] ([MitarbeiterNr], [Recht])
|
||||
VALUES {string.Join(", ", roles.Select((x, i) => $"('{employeeId}', '{new SqlParameter(i.ToString(), x).SqlValue}')"))}")
|
||||
.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace LaaProduction.Personalization.Repositories
|
||||
{
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
|
||||
using LaaProductionSQL.Interfaces;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal class SoftwareRepository : ISoftwareRepository
|
||||
{
|
||||
private readonly ISQLConnection sqlConnection;
|
||||
|
||||
public SoftwareRepository(ISQLConnection sqlConnection)
|
||||
=> this.sqlConnection = sqlConnection;
|
||||
|
||||
public short AppId(string software)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [AppID]
|
||||
FROM [VersionSoftwareAccess]
|
||||
WHERE [SoftwareAccess_Program] = @{nameof(software)}")
|
||||
.SetParameter(nameof(software), software)
|
||||
.FirstOrDefault(x => x.GetSmallint());
|
||||
|
||||
public IEnumerable<string> GetSoftwareFunctions(string token)
|
||||
=> this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
SELECT [SF].[Function]
|
||||
FROM [MitarbeiterTokens] AS [MT]
|
||||
JOIN [SoftwareFunctions] AS [SF]
|
||||
ON [SF].[AppId] = [MT].[AppId]
|
||||
WHERE [MT].[Token] = @{nameof(token)}")
|
||||
.SetParameter(nameof(token), token)
|
||||
.ExecuteReader(x => x.GetString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace LaaProduction.Personalization
|
||||
{
|
||||
using LaaProduction.Personalization.Repositories;
|
||||
using LaaProduction.Personalization.Repositories.Interfaces;
|
||||
|
||||
using LaaProductionSQL;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using System;
|
||||
|
||||
internal class ServiceProvider
|
||||
{
|
||||
private static IServiceProvider serviceProvider;
|
||||
|
||||
internal static T GetService<T>()
|
||||
=> serviceProvider.GetService<T>();
|
||||
|
||||
internal static void RegisterServices(string sqlConnectionString)
|
||||
{
|
||||
serviceProvider = new ServiceCollection()
|
||||
.AddSingleton(_ => SQLConnection.CreateConnection(sqlConnectionString))
|
||||
.AddScoped<IEmployeesRepository, EmployeesRepository>()
|
||||
.AddScoped<IRolesRepository, RolesRepository>()
|
||||
.AddScoped<ISoftwareRepository, SoftwareRepository>()
|
||||
.BuildServiceProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace LaaProduction.Personalization
|
||||
{
|
||||
public enum SoftwareFunctions
|
||||
{
|
||||
DEV_FILE_CONTROL,
|
||||
DEV_FILE_SPLIT,
|
||||
DEV_LEGACY_TEST_APP,
|
||||
DEV_LOW_LEVEL_TOOLS,
|
||||
GENERAL_ALARM,
|
||||
GENERAL_FIRMWARE_UPDATE,
|
||||
GENERAL_LUT_MANAGEMENT,
|
||||
GENERAL_LUT_UPDATE,
|
||||
GENERAL_PRESSURE_LOG,
|
||||
GENERAL_PULS_CONFIG,
|
||||
GENERAL_REGISTER_STORE,
|
||||
GENERAL_SETUP,
|
||||
GENERAL_STREAM_QUALITY,
|
||||
GENERAL_TEMP_METER,
|
||||
LAA_MAPPING_NA,
|
||||
LAA_PARAMETERIZATION,
|
||||
LAA_PASSWORD,
|
||||
LAA_PROCESS_PARAMETER,
|
||||
LAA_REGISTER_HISTORY,
|
||||
Test_Func,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
namespace LaaProduction.Personalization
|
||||
{
|
||||
public enum UsersRoles
|
||||
{
|
||||
AV_ABFRAGE_GEPRUEFTE,
|
||||
AV_ABFRAGEN6SIGMA,
|
||||
AV_ABGEBROCHENEPRUEFGAENGE,
|
||||
AV_AUFTRAGPOSITION,
|
||||
AV_AUFTRAGSTORNO,
|
||||
AV_CDLWIN_VERWALTEN,
|
||||
AV_EICHSCHEIN,
|
||||
AV_eRegister,
|
||||
AV_FEHLERGRENZEN,
|
||||
AV_FERTIGMELDEN,
|
||||
AV_FREMDGERAETE,
|
||||
AV_LISTEPLOMBEN,
|
||||
AV_LIZENZEN_VERWALTEN,
|
||||
AV_MITTEILUNGEN,
|
||||
AV_PREUFSTATAUSLAST,
|
||||
AV_PRUEFERGEBNISSE,
|
||||
AV_PRUEFERGEBNISSEUMSCHREIBEN,
|
||||
AV_PRUEFFEHLER_FREIGABE,
|
||||
AV_PRUEFPUNKTEAENDERN,
|
||||
AV_RECHTE,
|
||||
AV_REGULIERERINFOS,
|
||||
AV_REPARATUR,
|
||||
AV_RUECKLAEUFER,
|
||||
AV_RZDATEN,
|
||||
AV_RZFEHLER,
|
||||
AV_SENSUSREAD_LESEN,
|
||||
AV_SENSUSREAD_VERWALTEN,
|
||||
AV_SENSUSREADLIZENZEN,
|
||||
AV_SERIENDRUCK,
|
||||
AV_SONDERAUFTRAEGE,
|
||||
AV_SQL_1,
|
||||
AV_SQL_4,
|
||||
AV_SQL_7,
|
||||
AV_SQL_8,
|
||||
AV_SQLAbfragen,
|
||||
AV_TERMINTREUE,
|
||||
AV_TERMINVERZOEGERUNGEN,
|
||||
AV_TREFFERQUOTE,
|
||||
AV_VAKODECODE,
|
||||
AV_VERSANDINFO,
|
||||
AV_VORGANGSNR,
|
||||
DRUCKPRUEFER,
|
||||
eRegister_Freigabe,
|
||||
PDA_EICHUNG,
|
||||
PREUFSTATAUSLAST,
|
||||
PROT_DRUCK_BEI_ABWEICHUNG,
|
||||
PRUEFER,
|
||||
PRUEFSTELLENLEITUNG,
|
||||
SUPERUSER,
|
||||
TEST,
|
||||
WEB_Admin,
|
||||
WEB_API_Explorer,
|
||||
WEB_HeReport,
|
||||
WEB_PalettenScan,
|
||||
WEB_ProdApproval,
|
||||
WEB_PuneProtokoll,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user