Dynamic user profile per tenant
This commit is contained in:
73
Oqtane.Server/Controllers/ProfileController.cs
Normal file
73
Oqtane.Server/Controllers/ProfileController.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route("{site}/api/[controller]")]
|
||||
public class ProfileController : Controller
|
||||
{
|
||||
private readonly IProfileRepository Profiles;
|
||||
|
||||
public ProfileController(IProfileRepository Profiles)
|
||||
{
|
||||
this.Profiles = Profiles;
|
||||
}
|
||||
|
||||
// GET: api/<controller>?siteid=x
|
||||
[HttpGet]
|
||||
public IEnumerable<Profile> Get(string siteid)
|
||||
{
|
||||
if (siteid == "")
|
||||
{
|
||||
return Profiles.GetProfiles();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Profiles.GetProfiles(int.Parse(siteid));
|
||||
}
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
public Profile Get(int id)
|
||||
{
|
||||
return Profiles.GetProfile(id);
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public Profile Post([FromBody] Profile Profile)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
Profile = Profiles.AddProfile(Profile);
|
||||
}
|
||||
return Profile;
|
||||
}
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public Profile Put(int id, [FromBody] Profile Profile)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
Profile = Profiles.UpdateProfile(Profile);
|
||||
}
|
||||
return Profile;
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
Profiles.DeleteProfile(id);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ namespace Oqtane.Repository
|
||||
public virtual DbSet<PageModule> PageModule { get; set; }
|
||||
public virtual DbSet<Module> Module { get; set; }
|
||||
public virtual DbSet<User> User { get; set; }
|
||||
public virtual DbSet<Profile> Profile { get; set; }
|
||||
public virtual DbSet<SiteUser> SiteUser { get; set; }
|
||||
public virtual DbSet<Role> Role { get; set; }
|
||||
public virtual DbSet<UserRole> UserRole { get; set; }
|
||||
|
15
Oqtane.Server/Repository/Interfaces/IProfileRepository.cs
Normal file
15
Oqtane.Server/Repository/Interfaces/IProfileRepository.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public interface IProfileRepository
|
||||
{
|
||||
IEnumerable<Profile> GetProfiles();
|
||||
IEnumerable<Profile> GetProfiles(int SiteId);
|
||||
Profile AddProfile(Profile Profile);
|
||||
Profile UpdateProfile(Profile Profile);
|
||||
Profile GetProfile(int ProfileId);
|
||||
void DeleteProfile(int ProfileId);
|
||||
}
|
||||
}
|
53
Oqtane.Server/Repository/ProfileRepository.cs
Normal file
53
Oqtane.Server/Repository/ProfileRepository.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
public class ProfileRepository : IProfileRepository
|
||||
{
|
||||
private TenantDBContext db;
|
||||
|
||||
public ProfileRepository(TenantDBContext context)
|
||||
{
|
||||
db = context;
|
||||
}
|
||||
|
||||
public IEnumerable<Profile> GetProfiles()
|
||||
{
|
||||
return db.Profile;
|
||||
}
|
||||
|
||||
public IEnumerable<Profile> GetProfiles(int SiteId)
|
||||
{
|
||||
return db.Profile.Where(item => item.SiteId == SiteId);
|
||||
}
|
||||
|
||||
public Profile AddProfile(Profile Profile)
|
||||
{
|
||||
db.Profile.Add(Profile);
|
||||
db.SaveChanges();
|
||||
return Profile;
|
||||
}
|
||||
|
||||
public Profile UpdateProfile(Profile Profile)
|
||||
{
|
||||
db.Entry(Profile).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Profile;
|
||||
}
|
||||
|
||||
public Profile GetProfile(int ProfileId)
|
||||
{
|
||||
return db.Profile.Find(ProfileId);
|
||||
}
|
||||
|
||||
public void DeleteProfile(int ProfileId)
|
||||
{
|
||||
Profile Profile = db.Profile.Find(ProfileId);
|
||||
db.Profile.Remove(Profile);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
@ -183,6 +183,8 @@ CREATE TABLE [dbo].[Profile](
|
||||
[ProfileId] [int] IDENTITY(1,1) NOT NULL,
|
||||
[SiteId] [int] NULL,
|
||||
[Name] [nvarchar](50) NOT NULL,
|
||||
[Title] [nvarchar](50) NOT NULL,
|
||||
[Description] [nvarchar](256) NULL,
|
||||
[Category] [nvarchar](50) NOT NULL,
|
||||
[ViewOrder] [int] NOT NULL,
|
||||
[MaxLength] [int] NOT NULL,
|
||||
@ -378,6 +380,35 @@ GO
|
||||
SET IDENTITY_INSERT [dbo].[Role] OFF
|
||||
GO
|
||||
|
||||
SET IDENTITY_INSERT [dbo].[Profile] ON
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (1, 1, 'FirstName', 'First Name', 'Your First Or Given Name', 'Name', 1, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (2, 1, 'LastName', 'Last Name', 'Your Last Or family Name', 'Name', 2, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (3, 1, 'Street', 'Street', 'Street Or Building Address', 'Address', 3, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (4, 1, 'City', 'City', 'City', 'Address', 4, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (5, 1, 'Region', 'Region', 'State Or Province', 'Address', 5, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (6, 1, 'Country', 'Country', 'Country', 'Address', 6, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (7, 1, 'PostalCode', 'Postal Code', 'Postal Code Or Zip Code', 'Address', 7, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (8, 1, 'Phone', 'Phone Number', 'Phone Number', 'Contact', 8, 50, '', 1, 0, '', getdate(), '', getdate())
|
||||
GO
|
||||
SET IDENTITY_INSERT [dbo].[Profile] OFF
|
||||
GO
|
||||
|
||||
SET IDENTITY_INSERT [dbo].[Page] ON
|
||||
GO
|
||||
INSERT [dbo].[Page] ([PageId], [SiteId], [Name], [Path], [ThemeType], [Icon], [Panes], [ParentId], [Order], [IsNavigation], [LayoutType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
@ -508,6 +539,15 @@ INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName],
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 16, 'Edit', 1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Page] ([PageId], [SiteId], [Name], [Path], [ThemeType], [Icon], [Panes], [ParentId], [Order], [IsNavigation], [LayoutType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (17, 1, N'Profile', N'profile', N'Oqtane.Client.Themes.Theme2.Theme2, Oqtane.Client', N'', N'Top;Bottom', NULL, 1, 0, N'', '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 17, 'View', -1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 17, 'View', 1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Page', 17, 'Edit', 1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
SET IDENTITY_INSERT [dbo].[Page] OFF
|
||||
GO
|
||||
|
||||
@ -677,6 +717,15 @@ INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName],
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 20, 'Edit', 1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Module] ([ModuleId], [SiteId], [ModuleDefinitionName], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (21, 1, N'Oqtane.Client.Modules.Admin.Profile, Oqtane.Client', '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 21, 'View', -1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 21, 'View', 1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[Permission] ([SiteId], [EntityName], [EntityId], [PermissionName], [RoleId], [UserId], [IsAuthorized], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) VALUES (1, 'Module', 21, 'Edit', 1, null, 1, '', getdate(), '', getdate())
|
||||
GO
|
||||
SET IDENTITY_INSERT [dbo].[Module] OFF
|
||||
GO
|
||||
|
||||
@ -742,6 +791,9 @@ GO
|
||||
INSERT [dbo].[PageModule] ([PageModuleId], [PageId], [ModuleId], [Title], [Pane], [Order], [ContainerType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (20, 16, 20, N'Role Management', N'Top', 0, N'Oqtane.Client.Themes.Theme2.Container2, Oqtane.Client', '', getdate(), '', getdate())
|
||||
GO
|
||||
INSERT [dbo].[PageModule] ([PageModuleId], [PageId], [ModuleId], [Title], [Pane], [Order], [ContainerType], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
|
||||
VALUES (21, 17, 21, N'User Profile', N'Top', 0, N'Oqtane.Client.Themes.Theme2.Container2, Oqtane.Client', '', getdate(), '', getdate())
|
||||
GO
|
||||
SET IDENTITY_INSERT [dbo].[PageModule] OFF
|
||||
GO
|
||||
|
||||
|
@ -91,6 +91,7 @@ namespace Oqtane.Server
|
||||
services.AddScoped<IModuleService, ModuleService>();
|
||||
services.AddScoped<IPageModuleService, PageModuleService>();
|
||||
services.AddScoped<IUserService, UserService>();
|
||||
services.AddScoped<IProfileService, ProfileService>();
|
||||
services.AddScoped<IRoleService, RoleService>();
|
||||
services.AddScoped<IUserRoleService, UserRoleService>();
|
||||
services.AddScoped<ISettingService, SettingService>();
|
||||
@ -178,6 +179,7 @@ namespace Oqtane.Server
|
||||
services.AddTransient<IModuleRepository, ModuleRepository>();
|
||||
services.AddTransient<IPageModuleRepository, PageModuleRepository>();
|
||||
services.AddTransient<IUserRepository, UserRepository>();
|
||||
services.AddTransient<IProfileRepository, ProfileRepository>();
|
||||
services.AddTransient<ISiteUserRepository, SiteUserRepository>();
|
||||
services.AddTransient<IRoleRepository, RoleRepository>();
|
||||
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
|
||||
|
Reference in New Issue
Block a user