Merge branch 'release/rc-v1.2.0' of github.com:ONLYOFFICE/AppServer into release/rc-v1.2.0
This commit is contained in:
commit
6f2d00d57f
@ -24,13 +24,13 @@
|
||||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
||||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ASC.Migration.PersonalToDocspace.Creator;
|
||||
|
||||
[Scope]
|
||||
public class MigrationCreator
|
||||
{
|
||||
private readonly IHostEnvironment _hostEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly TenantDomainValidator _tenantDomainValidator;
|
||||
private readonly TempStream _tempStream;
|
||||
private readonly DbFactory _dbFactory;
|
||||
@ -40,7 +40,8 @@ public class MigrationCreator
|
||||
|
||||
private List<IModuleSpecifics> _modules;
|
||||
private string _pathToSave;
|
||||
private string _userName;
|
||||
private string _userName;
|
||||
private string _mail;
|
||||
private string _toRegion;
|
||||
private int _tenant;
|
||||
private readonly object _locker = new object();
|
||||
@ -54,9 +55,9 @@ public class MigrationCreator
|
||||
ModuleName.WebStudio
|
||||
};
|
||||
|
||||
public string NewAlias { get; private set; }
|
||||
|
||||
public MigrationCreator(
|
||||
IHostEnvironment hostEnvironment,
|
||||
IConfiguration configuration,
|
||||
TenantDomainValidator tenantDomainValidator,
|
||||
TempStream tempStream,
|
||||
DbFactory dbFactory,
|
||||
@ -64,8 +65,6 @@ public class MigrationCreator
|
||||
StorageFactoryConfig storageFactoryConfig,
|
||||
ModuleProvider moduleProvider)
|
||||
{
|
||||
_hostEnvironment = hostEnvironment;
|
||||
_configuration = configuration;
|
||||
_tenantDomainValidator = tenantDomainValidator;
|
||||
_tempStream = tempStream;
|
||||
_dbFactory = dbFactory;
|
||||
@ -74,11 +73,11 @@ public class MigrationCreator
|
||||
_moduleProvider = moduleProvider;
|
||||
}
|
||||
|
||||
public string Create(int tenant, string userName, string toRegion)
|
||||
public string Create(int tenant, string userName, string mail, string toRegion)
|
||||
{
|
||||
Init(tenant, userName, toRegion);
|
||||
Init(tenant, userName, mail, toRegion);
|
||||
|
||||
var id = GetId();
|
||||
var id = GetUserId();
|
||||
var fileName = _userName + ".tar.gz";
|
||||
var path = Path.Combine(_pathToSave, fileName);
|
||||
using (var writer = new ZipWriteOperator(_tempStream, path))
|
||||
@ -89,22 +88,40 @@ public class MigrationCreator
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private void Init(int tenant, string userName, string toRegion)
|
||||
private void Init(int tenant, string userName, string mail, string toRegion)
|
||||
{
|
||||
_modules = _moduleProvider.AllModules.Where(m => _namesModules.Contains(m.ModuleName)).ToList();
|
||||
|
||||
_pathToSave = "";
|
||||
_toRegion = toRegion;
|
||||
_userName = userName;
|
||||
_userName = userName;
|
||||
_mail = mail;
|
||||
_tenant = tenant;
|
||||
}
|
||||
|
||||
private Guid GetId()
|
||||
private Guid GetUserId()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userDbContext = _dbFactory.CreateDbContext<UserDbContext>();
|
||||
return userDbContext.Users.FirstOrDefault(q => q.Tenant == _tenant && q.Status == EmployeeStatus.Active && q.UserName == _userName).Id;
|
||||
var userDbContext = _dbFactory.CreateDbContext<UserDbContext>();
|
||||
User user = null;
|
||||
if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_mail))
|
||||
{
|
||||
if (string.IsNullOrEmpty(_userName))
|
||||
{
|
||||
user = userDbContext.Users.FirstOrDefault(q => q.Tenant == _tenant && q.Status == EmployeeStatus.Active && q.Email == _mail);
|
||||
_userName = user.UserName;
|
||||
}
|
||||
else
|
||||
{
|
||||
user = userDbContext.Users.FirstOrDefault(q => q.Tenant == _tenant && q.Status == EmployeeStatus.Active && q.UserName == _userName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
user = userDbContext.Users.FirstOrDefault(q => q.Tenant == _tenant && q.Status == EmployeeStatus.Active && q.UserName == _userName && q.Email == _mail);
|
||||
}
|
||||
return user.Id;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@ -162,11 +179,6 @@ public class MigrationCreator
|
||||
ChangeAlias(data);
|
||||
ChangeName(data);
|
||||
}
|
||||
|
||||
if (data.TableName == "files_bunch_objects")
|
||||
{
|
||||
RemoveGeneralBunchObjects(data);
|
||||
}
|
||||
|
||||
using (var file = _tempStream.Create())
|
||||
{
|
||||
@ -185,39 +197,51 @@ public class MigrationCreator
|
||||
private void ChangeAlias(DataTable data)
|
||||
{
|
||||
var aliases = GetAliases();
|
||||
var newAlias = _userName;
|
||||
NewAlias = _userName;
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
_tenantDomainValidator.ValidateDomainLength(newAlias);
|
||||
_tenantDomainValidator.ValidateDomainCharacters(newAlias);
|
||||
if (aliases.Contains(newAlias))
|
||||
{
|
||||
NewAlias = RemoveInvalidCharacters(NewAlias);
|
||||
_tenantDomainValidator.ValidateDomainLength(NewAlias);
|
||||
_tenantDomainValidator.ValidateDomainCharacters(NewAlias);
|
||||
if (aliases.Contains(NewAlias))
|
||||
{
|
||||
throw new Exception($"Alias is busy");
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (TenantTooShortException ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
newAlias = Console.ReadLine();
|
||||
if (NewAlias.Length > 100)
|
||||
{
|
||||
NewAlias = NewAlias.Substring(0, 50);
|
||||
}
|
||||
else
|
||||
{
|
||||
NewAlias = $"DocSpace{NewAlias}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var last = NewAlias.Substring(NewAlias.Length-1);
|
||||
if (int.TryParse(last, out var lastNumber))
|
||||
{
|
||||
NewAlias = NewAlias.Substring(0, NewAlias.Length - 1) + (lastNumber + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
NewAlias = NewAlias + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var q = data.Rows[0];
|
||||
data.Rows[0]["alias"] = newAlias;
|
||||
Console.WriteLine($"Alias is - {NewAlias}");
|
||||
data.Rows[0]["alias"] = NewAlias;
|
||||
}
|
||||
|
||||
private void RemoveGeneralBunchObjects(DataTable data)
|
||||
private string RemoveInvalidCharacters(string alias)
|
||||
{
|
||||
for(var i = 0; i < data.Rows.Count; i++)
|
||||
{
|
||||
if (data.Rows[i]["right_node"].ToString().EndsWith('/'))
|
||||
{
|
||||
data.Rows.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return Regex.Replace(alias, "[^a-z0-9]", "", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
private List<string> GetAliases()
|
||||
|
@ -81,6 +81,7 @@ public class MigrationRunner
|
||||
|
||||
await DoRestoreStorage(dataReader, columnMapper);
|
||||
|
||||
SetAdmin(columnMapper.GetTenantMapping());
|
||||
SetTenantActive(columnMapper.GetTenantMapping());
|
||||
}
|
||||
}
|
||||
@ -145,5 +146,27 @@ public class MigrationRunner
|
||||
tenant.StatusChanged = DateTime.UtcNow;
|
||||
dbContext.Tenants.Update(tenant);
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
private void SetAdmin(int tenantId)
|
||||
{
|
||||
using var dbContextTenant = _dbFactory.CreateDbContext<TenantDbContext>(_region);
|
||||
var tenant = dbContextTenant.Tenants.Single(t => t.Id == tenantId);
|
||||
using var dbContextUser = _dbFactory.CreateDbContext<UserDbContext>(_region);
|
||||
|
||||
if (!dbContextUser.UserGroups.Any(q => q.Tenant == tenantId)) {
|
||||
var userGroup = new UserGroup()
|
||||
{
|
||||
Tenant = tenantId,
|
||||
LastModified = DateTime.UtcNow,
|
||||
RefType = Core.UserGroupRefType.Contains,
|
||||
Removed = false,
|
||||
UserGroupId = ASC.Common.Security.Authorizing.Constants.DocSpaceAdmin.ID,
|
||||
Userid = tenant.OwnerId.Value
|
||||
};
|
||||
|
||||
dbContextUser.UserGroups.Add(userGroup);
|
||||
dbContextUser.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +86,15 @@ builder.WebHost.ConfigureServices((hostContext, services) =>
|
||||
|
||||
});
|
||||
|
||||
if(string.IsNullOrEmpty(param.UserName) && string.IsNullOrEmpty(param.Mail))
|
||||
{
|
||||
throw new Exception("username or email must be entered");
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
Console.WriteLine("backup start");
|
||||
var migrationCreator = app.Services.GetService<MigrationCreator>();
|
||||
var fileName = migrationCreator.Create(param.Tenant, param.UserName, param.ToRegion);
|
||||
var fileName = migrationCreator.Create(param.Tenant, param.UserName, param.Mail, param.ToRegion);
|
||||
Console.WriteLine("backup was success");
|
||||
Console.WriteLine("restore start");
|
||||
var migrationRunner = app.Services.GetService<MigrationRunner>();
|
||||
@ -104,15 +109,19 @@ if (Directory.Exists(AppContext.BaseDirectory + "\\temp"))
|
||||
}
|
||||
|
||||
Console.WriteLine("migration was success");
|
||||
Console.WriteLine($"new alias is - {migrationCreator.NewAlias}");
|
||||
|
||||
public sealed class Options
|
||||
{
|
||||
[Option('t', "tenant", Required = true)]
|
||||
public int Tenant { get; set; }
|
||||
|
||||
[Option('u', "username", Required = true)]
|
||||
[Option('u', "username", Required = false, HelpText = "enter username or mail for find user")]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[Option('m', "mail", Required = false, HelpText = "enter username or mail for find user")]
|
||||
public string Mail { get; set; }
|
||||
|
||||
[Option("toregion", Required = true)]
|
||||
public string ToRegion { get; set; }
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import styled, { css } from "styled-components";
|
||||
|
||||
import { Base } from "@docspace/components/themes";
|
||||
import { mobile } from "@docspace/components/utils/device";
|
||||
import { mobile, tablet } from "@docspace/components/utils/device";
|
||||
|
||||
const StyledInfoPanelBody = styled.div`
|
||||
${({ isAccounts }) =>
|
||||
@ -45,6 +45,11 @@ const StyledTitle = styled.div`
|
||||
background: ${(props) => props.theme.infoPanel.backgroundColor};
|
||||
z-index: 100;
|
||||
|
||||
@media ${tablet} {
|
||||
width: 440px;
|
||||
padding: 24px 0 24px 20px;
|
||||
}
|
||||
|
||||
@media ${mobile} {
|
||||
width: calc(100% - 32px);
|
||||
padding: 24px 0 24px 16px;
|
||||
|
@ -13,8 +13,8 @@ const CommonSettings = ({
|
||||
forceSave,
|
||||
|
||||
isVisitor,
|
||||
favoritesSection,
|
||||
recentSection,
|
||||
//favoritesSection,
|
||||
//recentSection,
|
||||
|
||||
setUpdateIfExist,
|
||||
setStoreOriginal,
|
||||
@ -82,12 +82,14 @@ const CommonSettings = ({
|
||||
onChange={onChangeOriginalCopy}
|
||||
isChecked={storeOriginalFiles}
|
||||
/>
|
||||
<ToggleButton
|
||||
className="toggle-btn"
|
||||
label={t("DisplayNotification")}
|
||||
onChange={onChangeDeleteConfirm}
|
||||
isChecked={confirmDelete}
|
||||
/>
|
||||
{!isVisitor && (
|
||||
<ToggleButton
|
||||
className="toggle-btn"
|
||||
label={t("DisplayNotification")}
|
||||
onChange={onChangeDeleteConfirm}
|
||||
isChecked={confirmDelete}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{/* <Box className="settings-section">
|
||||
|
@ -298,7 +298,7 @@ class ContextOptionsStore {
|
||||
)
|
||||
: null;
|
||||
|
||||
this.filesStore.openDocEditor(id, providerKey, tab, urlFormation);
|
||||
this.filesStore.openDocEditor(id, providerKey, tab, urlFormation, preview);
|
||||
};
|
||||
|
||||
isPwa = () => {
|
||||
|
@ -2736,9 +2736,15 @@ class FilesStore {
|
||||
return folderInfo;
|
||||
};
|
||||
|
||||
openDocEditor = (id, providerKey = null, tab = null, url = null) => {
|
||||
openDocEditor = (
|
||||
id,
|
||||
providerKey = null,
|
||||
tab = null,
|
||||
url = null,
|
||||
preview = false
|
||||
) => {
|
||||
const foundIndex = this.files.findIndex((x) => x.id === id);
|
||||
if (foundIndex !== -1) {
|
||||
if (foundIndex !== -1 && !preview) {
|
||||
this.updateSelectionStatus(
|
||||
id,
|
||||
this.files[foundIndex].fileStatus | FileStatus.IsEditing,
|
||||
|
Loading…
Reference in New Issue
Block a user