improve user import API
This commit is contained in:
parent
5c86ef6682
commit
057fd02e26
|
@ -379,7 +379,26 @@ namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
if (int.TryParse(siteid, out int SiteId) && SiteId == _tenantManager.GetAlias().SiteId && int.TryParse(fileid, out int FileId) && bool.TryParse(notify, out bool Notify))
|
if (int.TryParse(siteid, out int SiteId) && SiteId == _tenantManager.GetAlias().SiteId && int.TryParse(fileid, out int FileId) && bool.TryParse(notify, out bool Notify))
|
||||||
{
|
{
|
||||||
return await _userManager.ImportUsers(SiteId, FileId, Notify);
|
var file = _files.GetFile(FileId);
|
||||||
|
if (file != null)
|
||||||
|
{
|
||||||
|
if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.PermissionList))
|
||||||
|
{
|
||||||
|
return await _userManager.ImportUsers(SiteId, _files.GetFilePath(file), Notify);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Import Attempt {SiteId} {FileId}", siteid, fileid);
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Import File Does Not Exist {SiteId} {FileId}", siteid, fileid);
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,6 @@ namespace Oqtane.Managers
|
||||||
User VerifyTwoFactor(User user, string token);
|
User VerifyTwoFactor(User user, string token);
|
||||||
Task<User> LinkExternalAccount(User user, string token, string type, string key, string name);
|
Task<User> LinkExternalAccount(User user, string token, string type, string key, string name);
|
||||||
Task<bool> ValidatePassword(string password);
|
Task<bool> ValidatePassword(string password);
|
||||||
Task<Dictionary<string, string>> ImportUsers(int siteId, int fileId, bool notify);
|
Task<Dictionary<string, string>> ImportUsers(int siteId, string filePath, bool notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -466,17 +466,13 @@ namespace Oqtane.Managers
|
||||||
return result.Succeeded;
|
return result.Succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, string>> ImportUsers(int siteId, int fileId, bool notify)
|
public async Task<Dictionary<string, string>> ImportUsers(int siteId, string filePath, bool notify)
|
||||||
{
|
{
|
||||||
var success = true;
|
var success = true;
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
int users = 0;
|
int users = 0;
|
||||||
|
|
||||||
var file = _files.GetFile(fileId);
|
if (System.IO.File.Exists(filePath))
|
||||||
if (file != null)
|
|
||||||
{
|
|
||||||
var path = _files.GetFilePath(file);
|
|
||||||
if (System.IO.File.Exists(path))
|
|
||||||
{
|
{
|
||||||
var roles = _roles.GetRoles(siteId).ToList();
|
var roles = _roles.GetRoles(siteId).ToList();
|
||||||
var profiles = _profiles.GetProfiles(siteId).ToList();
|
var profiles = _profiles.GetProfiles(siteId).ToList();
|
||||||
|
@ -484,7 +480,7 @@ namespace Oqtane.Managers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string row = "";
|
string row = "";
|
||||||
using (var reader = new StreamReader(path))
|
using (var reader = new StreamReader(filePath))
|
||||||
{
|
{
|
||||||
// header row
|
// header row
|
||||||
if (reader.Peek() > -1)
|
if (reader.Peek() > -1)
|
||||||
|
@ -637,19 +633,13 @@ namespace Oqtane.Managers
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Error Importing User Import File {SiteId} {FileId}", siteId, fileId);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Error Importing User Import File {SiteId} {FilePath} {Notify}", siteId, filePath, notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Import File Does Not Exist {Path}", path);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Import File Does Not Exist {FilePath}", filePath);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = false;
|
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Import File Does Not Exist {SiteId} {FileId}", siteId, fileId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return results
|
// return results
|
||||||
|
|
Loading…
Reference in New Issue
Block a user