From d235288370bdcf7b9198c8a9671726fcc7a35a15 Mon Sep 17 00:00:00 2001 From: Alexey Bannov Date: Mon, 15 Nov 2021 19:36:09 +0300 Subject: [PATCH 1/4] refactoring build script --- build/build.backend.bat | 5 ++++- build/build.bat | 21 +++++++++++++++------ build/build.static.bat | 13 +++++++++++-- build/buildAndDeploy.PERSONAL.bat | 6 ++++++ build/buildAndDeploy.bat | 18 ++++++++++++------ build/runasadmin.bat | 1 - build/start/restart.bat | 12 ++++++++++-- build/start/start.bat | 7 ++----- build/start/start.ps1 | 19 +++++++++++++++++++ build/start/stop.bat | 10 +++++++++- 10 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 build/start/start.ps1 diff --git a/build/build.backend.bat b/build/build.backend.bat index d84130726f..a0b36d3589 100644 --- a/build/build.backend.bat +++ b/build/build.backend.bat @@ -1,6 +1,7 @@ +@echo off + PUSHD %~dp0.. dotnet build ASC.Web.slnf /fl1 /flp1:LogFile=build/ASC.Web.log;Verbosity=Normal -@echo off echo. echo Install nodejs projects dependencies... echo. @@ -15,6 +16,8 @@ if %errorlevel% == 0 ( echo. +POPD + if "%1"=="nopause" goto start pause :start \ No newline at end of file diff --git a/build/build.bat b/build/build.bat index a6afe940db..868b4eb304 100644 --- a/build/build.bat +++ b/build/build.bat @@ -1,18 +1,27 @@ +@echo off + +echo "##########################################################" +echo "######### Start build and deploy #######################" +echo "##########################################################" + +echo. + PUSHD %~dp0 call runasadmin.bat "%~dpnx0" + if %errorlevel% == 0 ( -call start\stop.bat - -PUSHD %~dp0.. +call start\stop.bat nopause echo "FRONT-END (for start run command 'yarn start' inside the root folder)" -call build\build.frontend.bat +call build.frontend.bat nopause echo "BACK-END" -call build\build.backend.bat +call build.backend.bat nopause -start /b call build\start\start.bat +call start\start.bat nopause + +echo. pause ) \ No newline at end of file diff --git a/build/build.static.bat b/build/build.static.bat index f0a4cfebf8..6d6b2c4df8 100644 --- a/build/build.static.bat +++ b/build/build.static.bat @@ -48,15 +48,24 @@ powershell -Command "(gc build\deploy\nginx\sites-enabled\onlyoffice-studio.conf REM restart nginx echo service nginx stop -call sc stop nginx +call sc stop nginx > nul REM sleep 5 seconds call ping 127.0.0.1 -n 6 > nul echo service nginx start -call sc start nginx +call sc start nginx > nul + +if NOT %errorlevel% == 0 ( + echo Couldn't restarte Onlyoffice%%~nf service ) +) + +echo. + +POPD + if "%1"=="nopause" goto start pause :start \ No newline at end of file diff --git a/build/buildAndDeploy.PERSONAL.bat b/build/buildAndDeploy.PERSONAL.bat index aa1b1e7b1e..d89a6d053a 100644 --- a/build/buildAndDeploy.PERSONAL.bat +++ b/build/buildAndDeploy.PERSONAL.bat @@ -1,3 +1,9 @@ +echo "##########################################################" +echo "######### Start build and deploy Personal ##############" +echo "##########################################################" + +echo. + PUSHD %~dp0 call runasadmin.bat "%~dpnx0" if %errorlevel% == 0 ( diff --git a/build/buildAndDeploy.bat b/build/buildAndDeploy.bat index 64927a481c..af3f52ca0a 100644 --- a/build/buildAndDeploy.bat +++ b/build/buildAndDeploy.bat @@ -1,5 +1,11 @@ @echo off -PUSHD %~dp0 + +echo "##########################################################" +echo "######### Start build and deploy #######################" +echo "##########################################################" + +echo. + setlocal EnableDelayedExpansion call runasadmin.bat "%~dpnx0" @@ -8,15 +14,15 @@ if %errorlevel% == 0 ( call start\stop.bat nopause -PUSHD %~dp0.. - echo "FRONT-END static" -call build\build.static.bat nopause +call build.static.bat nopause echo "BACK-END" -call build\build.backend.bat nopause +call build.backend.bat nopause -call build\start\start.bat nopause +call start\start.bat nopause + +echo. pause ) \ No newline at end of file diff --git a/build/runasadmin.bat b/build/runasadmin.bat index 73b0a1958d..6298efa01b 100644 --- a/build/runasadmin.bat +++ b/build/runasadmin.bat @@ -23,6 +23,5 @@ if '%errorlevel%' NEQ '0' ( exit /B 1 :gotAdmin - pushd "%CD%" CD /D "%~dp0" :-------------------------------------- \ No newline at end of file diff --git a/build/start/restart.bat b/build/start/restart.bat index 256665750f..2f89bbc7f4 100644 --- a/build/start/restart.bat +++ b/build/start/restart.bat @@ -5,11 +5,19 @@ call runasadmin.bat "%~dpnx0" if %errorlevel% == 0 ( for /R "run\" %%f in (*.bat) do ( - call sc stop "Onlyoffice%%~nf" - call sc start "Onlyoffice%%~nf" + call sc stop "Onlyoffice%%~nf" > nul + call sc start "Onlyoffice%%~nf" > nul + + if %errorlevel% == 0 ( + echo Onlyoffice%%~nf service has been restarted + ) else ( + echo Couldn't restarte Onlyoffice%%~nf service + ) ) ) +POPD + echo. if "%1"=="nopause" goto start diff --git a/build/start/start.bat b/build/start/start.bat index 9ecf6aa69e..c21a506fc2 100644 --- a/build/start/start.bat +++ b/build/start/start.bat @@ -3,11 +3,8 @@ PUSHD %~dp0.. call runasadmin.bat "%~dpnx0" -if %errorlevel% == 0 ( - for /R "run\" %%f in (*.bat) do ( - call sc start "Onlyoffice%%~nf" - ) -) +POPD +powershell %~dp0/start.ps1 echo. diff --git a/build/start/start.ps1 b/build/start/start.ps1 new file mode 100644 index 0000000000..a078a75073 --- /dev/null +++ b/build/start/start.ps1 @@ -0,0 +1,19 @@ +$WorkDir = "$(Split-Path -Parent $PSScriptRoot)\run" + +workflow StartServices-Runbook +{ +param( + [string]$WorkDir + ) + + foreach -parallel($s in Get-ChildItem -Path $WorkDir | ForEach-Object -Process {[System.IO.Path]::GetFileNameWithoutExtension($_)}) { + Start-Service -InputObject $(Get-Service -Name "Onlyoffice$s") + Write-Output "Onlyoffice$s service has been started" + } +} + +#Write-Output "Starting services at time: $(Get-Date -Format HH:mm:ss)" +#Write-Output "" +StartServices-Runbook $WorkDir +#Write-Output "" +#Write-Output "End start services at time: $(Get-Date -Format HH:mm:ss)" diff --git a/build/start/stop.bat b/build/start/stop.bat index b28a9c758f..3af0d52861 100644 --- a/build/start/stop.bat +++ b/build/start/stop.bat @@ -5,12 +5,20 @@ call runasadmin.bat "%~dpnx0" if %errorlevel% == 0 ( for /R "run\" %%f in (*.bat) do ( - call sc stop "Onlyoffice%%~nf" + call sc stop "Onlyoffice%%~nf" > nul + + if %errorlevel% == 0 ( + echo Onlyoffice%%~nf service has been stopped + ) else ( + echo Couldn't stop Onlyoffice%%~nf service + ) ) ) echo. +POPD + if "%1"=="nopause" goto start pause :start \ No newline at end of file From f0cfeb1b42bb8d8ff19942903d5c6ac1334882a3 Mon Sep 17 00:00:00 2001 From: Alexey Bannov Date: Tue, 16 Nov 2021 16:13:13 +0300 Subject: [PATCH 2/4] refactoring build script --- build/start/command.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 build/start/command.ps1 diff --git a/build/start/command.ps1 b/build/start/command.ps1 new file mode 100644 index 0000000000..8eef959102 --- /dev/null +++ b/build/start/command.ps1 @@ -0,0 +1,33 @@ +$PSversionMajor = $PSVersionTable.PSVersion | sort-object major | ForEach-Object {$_.major} +$PSversionMinor = $PSVersionTable.PSVersion | sort-object minor | ForEach-Object {$_.minor} + +if ($PSversionMajor -lt 7 -or $PSversionMinor -lt 2) { + Write-Error "Powershell version must be greater than or equal to 7.2. Press Enter to exit." + Pause + exit +} + +$WorkDir = "$(Split-Path -Parent $PSScriptRoot)\run"; +$CommandName = "$($args[0])"; + +#Write-Output "Starting $($CommandName) services at time: $(Get-Date -Format HH:mm:ss)" +#Write-Output "" + +Get-ChildItem -Path $WorkDir | ForEach-Object -ThrottleLimit 20 -Parallel { + $ServiceName = "Onlyoffice$([System.IO.Path]::GetFileNameWithoutExtension($_))"; + + switch ( $Using:CommandName ) + { + "start" { Start-Service -InputObject $(Get-Service -Name "$ServiceName") } + "stop" { Stop-Service -InputObject $(Get-Service -Name "$ServiceName") } + "restart" { Restart-Service -InputObject $(Get-Service -Name "$ServiceName") } + } + + if( $? ) + { + Write-Output "$ServiceName $($Using:CommandName) service has been done" + } +} + +#Write-Output "" +#Write-Output "End $($CommandName) services at time: $(Get-Date -Format HH:mm:ss)" \ No newline at end of file From 62403e127a9d217ed89dc9e3b7b8ada1e8e99ea1 Mon Sep 17 00:00:00 2001 From: Alexey Bannov Date: Tue, 16 Nov 2021 16:14:21 +0300 Subject: [PATCH 3/4] refactoring build script --- build/start/restart.bat | 17 ++++------------- build/start/start.bat | 5 ++++- build/start/start.ps1 | 19 ------------------- build/start/stop.bat | 14 +++----------- 4 files changed, 11 insertions(+), 44 deletions(-) delete mode 100644 build/start/start.ps1 diff --git a/build/start/restart.bat b/build/start/restart.bat index 2f89bbc7f4..7a3bbff722 100644 --- a/build/start/restart.bat +++ b/build/start/restart.bat @@ -3,21 +3,12 @@ PUSHD %~dp0.. call runasadmin.bat "%~dpnx0" -if %errorlevel% == 0 ( - for /R "run\" %%f in (*.bat) do ( - call sc stop "Onlyoffice%%~nf" > nul - call sc start "Onlyoffice%%~nf" > nul - - if %errorlevel% == 0 ( - echo Onlyoffice%%~nf service has been restarted - ) else ( - echo Couldn't restarte Onlyoffice%%~nf service - ) - ) -) - POPD +if %errorlevel% == 0 ( + pwsh %~dp0/command.ps1 "restart" +) + echo. if "%1"=="nopause" goto start diff --git a/build/start/start.bat b/build/start/start.bat index c21a506fc2..66ddb75db4 100644 --- a/build/start/start.bat +++ b/build/start/start.bat @@ -4,7 +4,10 @@ PUSHD %~dp0.. call runasadmin.bat "%~dpnx0" POPD -powershell %~dp0/start.ps1 + +if %errorlevel% == 0 ( + pwsh %~dp0/command.ps1 "start" +) echo. diff --git a/build/start/start.ps1 b/build/start/start.ps1 deleted file mode 100644 index a078a75073..0000000000 --- a/build/start/start.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -$WorkDir = "$(Split-Path -Parent $PSScriptRoot)\run" - -workflow StartServices-Runbook -{ -param( - [string]$WorkDir - ) - - foreach -parallel($s in Get-ChildItem -Path $WorkDir | ForEach-Object -Process {[System.IO.Path]::GetFileNameWithoutExtension($_)}) { - Start-Service -InputObject $(Get-Service -Name "Onlyoffice$s") - Write-Output "Onlyoffice$s service has been started" - } -} - -#Write-Output "Starting services at time: $(Get-Date -Format HH:mm:ss)" -#Write-Output "" -StartServices-Runbook $WorkDir -#Write-Output "" -#Write-Output "End start services at time: $(Get-Date -Format HH:mm:ss)" diff --git a/build/start/stop.bat b/build/start/stop.bat index 3af0d52861..61fccbb9e9 100644 --- a/build/start/stop.bat +++ b/build/start/stop.bat @@ -3,22 +3,14 @@ PUSHD %~dp0.. call runasadmin.bat "%~dpnx0" -if %errorlevel% == 0 ( - for /R "run\" %%f in (*.bat) do ( - call sc stop "Onlyoffice%%~nf" > nul +POPD - if %errorlevel% == 0 ( - echo Onlyoffice%%~nf service has been stopped - ) else ( - echo Couldn't stop Onlyoffice%%~nf service - ) - ) +if %errorlevel% == 0 ( + pwsh %~dp0/command.ps1 "stop" ) echo. -POPD - if "%1"=="nopause" goto start pause :start \ No newline at end of file From 9ad5e54c1d43ef163d9c7a68acafc52a727e1f7f Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Thu, 18 Nov 2021 18:32:12 +0300 Subject: [PATCH 4/4] Files: optimization --- .../Core/Core/Security/FileSecurity.cs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/products/ASC.Files/Core/Core/Security/FileSecurity.cs b/products/ASC.Files/Core/Core/Security/FileSecurity.cs index 20c5b58876..8da56a2d79 100644 --- a/products/ASC.Files/Core/Core/Security/FileSecurity.cs +++ b/products/ASC.Files/Core/Core/Security/FileSecurity.cs @@ -205,7 +205,8 @@ namespace ASC.Files.Core.Security private IEnumerable WhoCan(FileEntry entry, FilesSecurityActions action) { - var shares = GetShares(entry); + var copyshares = GetShares(entry); + IEnumerable shares = copyshares.ToList(); FileShareRecord defaultShareRecord; @@ -318,7 +319,7 @@ namespace ASC.Files.Core.Security return new[] { x.Subject }; }) .Distinct() - .Where(x => Can(entry, x, action)) + .Where(x => Can(entry, x, action, copyshares)) .ToList(); } @@ -342,9 +343,9 @@ namespace ASC.Files.Core.Security return Filter(entries.Cast>(), FilesSecurityActions.Edit, AuthContext.CurrentAccount.ID).Cast>(); } - private bool Can(FileEntry entry, Guid userId, FilesSecurityActions action) + private bool Can(FileEntry entry, Guid userId, FilesSecurityActions action, IEnumerable shares = null) { - return Filter(new[] { entry }, action, userId).Any(); + return Filter(new[] { entry }, action, userId, shares).Any(); } private List, bool>> Can(IEnumerable> entry, Guid userId, FilesSecurityActions action) @@ -353,7 +354,7 @@ namespace ASC.Files.Core.Security return entry.Select(r => new Tuple, bool>(r, filtres.Any(a => a.ID.Equals(r.ID)))).ToList(); } - private IEnumerable> Filter(IEnumerable> entries, FilesSecurityActions action, Guid userId) + private IEnumerable> Filter(IEnumerable> entries, FilesSecurityActions action, Guid userId, IEnumerable shares = null) { if (entries == null || !entries.Any()) return Enumerable.Empty>(); @@ -383,8 +384,7 @@ namespace ASC.Files.Core.Security if (entries.Any(filter)) { - var subjects = GetUserSubjects(userId); - List shares = null; + List subjects = null; foreach (var e in entries.Where(filter)) { if (!AuthManager.GetAccountByID(TenantManager.GetCurrentTenant().TenantId, userId).IsAuthenticated && userId != FileConstant.ShareLinkId) @@ -514,12 +514,19 @@ namespace ASC.Files.Core.Security // administrator in Common has all right result.Add(e); continue; - } + } - if (shares == null) - { - shares = GetShares(entries).Join(subjects, r => r.Subject, s => s, (r, s) => r).ToList(); - // shares ordered by level + if (subjects == null) + { + subjects = GetUserSubjects(userId); + if (shares == null) + { + shares = GetShares(entries); + // shares ordered by level + } + shares = shares + .Join(subjects, r => r.Subject, s => s, (r, s) => r) + .ToList(); } FileShareRecord ace; @@ -705,7 +712,7 @@ namespace ASC.Files.Core.Security var records = securityDao.GetShares(subjects); var result = new List(); - result.AddRange(GetSharesForMe(records.Where(r=> r.EntryId.GetType() == typeof(int)), subjects, filterType, subjectGroup, subjectID, searchText, searchInContent, withSubfolders)); + result.AddRange(GetSharesForMe(records.Where(r => r.EntryId.GetType() == typeof(int)), subjects, filterType, subjectGroup, subjectID, searchText, searchInContent, withSubfolders)); result.AddRange(GetSharesForMe(records.Where(r => r.EntryId.GetType() == typeof(string)), subjects, filterType, subjectGroup, subjectID, searchText, searchInContent, withSubfolders)); return result; }