From 6366cb556970dfdcfc30b0215e8c1608d0cd70c3 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 16 Mar 2023 16:22:18 +0100 Subject: [PATCH 1/6] fixed deleting buckets method --- csharp/App/Backend/DataTypes/Methods/Installation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index e27b3be67..f3ec67b80 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -62,7 +62,7 @@ public static class InstallationMethods .WithArguments(new[] { "Resources/s3cmd.py", "rb", $"s3://{installation.Id}-{salt}", "--access_key", - apiKey + apiKey, "--secret_key", secret }); var x = await cmd.ExecuteBufferedAsync(); return x.ExitCode == 0; From 4eac790eaaad61dca35428014a56481727f3ddd7 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 16 Mar 2023 16:34:52 +0100 Subject: [PATCH 2/6] exchanged api keys for ones with specific restricted permissions --- .../Backend/DataTypes/Methods/Installation.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index f3ec67b80..be76d69a7 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -34,12 +34,11 @@ public static class InstallationMethods public static async Task CreateBucket(this Installation installation) { - //NOTE this key has all the rights, please be sure you know what you're doing + const String secret = "-T9TAqy9a3-0-xj7HKsFFJOCcxfRpcnL6OW5oOrOcWU"; - const String secret = "z8brNDUAbpktvyWZN1jMIrsQhavDgK2t4cb8GLvsxYg"; - - const String apiKey = "EXO277645911ee6bde3875e99ae"; + const String apiKey = "EXO87ca85e29dd412f1238f1cf0"; const String salt = "3e5b3069-214a-43ee-8d85-57d72000c19d"; + var cmd = Cli .Wrap("python3") .WithArguments(new[] @@ -48,14 +47,29 @@ public static class InstallationMethods apiKey, "--secret_key", secret }); var x = await cmd.ExecuteBufferedAsync(); + + //Updating the url in the db as to not needing to wait until the next + var cmd2 = Cli + .Wrap("python3") + .WithArguments(new[] + { + "Resources/s3cmd.py", "signurl", $"s3://{installation.Id}-{salt}", + TimeSpan.FromDays(1).TotalSeconds.ToString(), "--access_key", + apiKey, "--secret_key", secret + }); + + var y = await cmd2.ExecuteBufferedAsync(); + installation.S3Url = y.StandardOutput.Replace("\n", "").Replace(" ", ""); + + Db.Update(installation); + return x.ExitCode == 0; } public static async Task DeleteBucket(this Installation installation) { - //NOTE this key has all the rights, please be sure you know what you're doing - const String secret = "z8brNDUAbpktvyWZN1jMIrsQhavDgK2t4cb8GLvsxYg"; - const String apiKey = "EXO277645911ee6bde3875e99ae"; + const String secret = "-T9TAqy9a3-0-xj7HKsFFJOCcxfRpcnL6OW5oOrOcWU"; + const String apiKey = "EXO87ca85e29dd412f1238f1cf0"; const String salt = "3e5b3069-214a-43ee-8d85-57d72000c19d"; var cmd = Cli .Wrap("python3") From df65b48c8fd55e4766d7227bd69199751360d084 Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 16 Mar 2023 16:45:25 +0100 Subject: [PATCH 3/6] creating new folders and installations now gives you access to the new folder/installation --- csharp/App/Backend/DataTypes/Methods/Installation.cs | 5 ++--- csharp/App/Backend/DataTypes/Methods/Session.cs | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/csharp/App/Backend/DataTypes/Methods/Installation.cs b/csharp/App/Backend/DataTypes/Methods/Installation.cs index be76d69a7..608827041 100644 --- a/csharp/App/Backend/DataTypes/Methods/Installation.cs +++ b/csharp/App/Backend/DataTypes/Methods/Installation.cs @@ -48,7 +48,7 @@ public static class InstallationMethods }); var x = await cmd.ExecuteBufferedAsync(); - //Updating the url in the db as to not needing to wait until the next + //Updating the url in the db as not wait until the next bi-daily update var cmd2 = Cli .Wrap("python3") .WithArguments(new[] @@ -81,8 +81,7 @@ public static class InstallationMethods var x = await cmd.ExecuteBufferedAsync(); return x.ExitCode == 0; } - - + public static IEnumerable UsersWithAccess(this Installation installation) { return UsersWithDirectAccess(installation).Concat(UsersWithInheritedAccess(installation)); diff --git a/csharp/App/Backend/DataTypes/Methods/Session.cs b/csharp/App/Backend/DataTypes/Methods/Session.cs index 6cc3616c6..394aadafd 100644 --- a/csharp/App/Backend/DataTypes/Methods/Session.cs +++ b/csharp/App/Backend/DataTypes/Methods/Session.cs @@ -9,12 +9,13 @@ public static class SessionMethods public static Boolean Create(this Session? session, Folder? folder) { var user = session?.User; - + return user is not null && folder is not null && user.HasWriteAccess && user.HasAccessTo(folder.Parent()) - && Db.Create(folder); + && Db.Create(folder) + && Db.Create(new FolderAccess() { UserId = user.Id, FolderId = folder.Id }); } public static Boolean Update(this Session? session, Folder? folder) @@ -50,7 +51,8 @@ public static class SessionMethods && user.HasWriteAccess && user.HasAccessTo(installation.Parent()) && Db.Create(installation) - && InstallationMethods.CreateBucket(installation).Result; + && InstallationMethods.CreateBucket(installation).Result + && Db.Create(new InstallationAccess { UserId = user.Id, InstallationId = installation.Id }); } public static Boolean Update(this Session? session, Installation? installation) From 91a1c47328de42b02386b918765468f48dec417b Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 16 Mar 2023 16:52:20 +0100 Subject: [PATCH 4/6] various small comments --- csharp/App/Backend/DataTypes/Methods/Session.cs | 9 +++++---- csharp/App/Backend/DataTypes/Methods/User.cs | 6 ++---- csharp/App/Backend/Database/Create.cs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/csharp/App/Backend/DataTypes/Methods/Session.cs b/csharp/App/Backend/DataTypes/Methods/Session.cs index 394aadafd..5b8dfae0a 100644 --- a/csharp/App/Backend/DataTypes/Methods/Session.cs +++ b/csharp/App/Backend/DataTypes/Methods/Session.cs @@ -1,4 +1,3 @@ -using System.Security.Cryptography; using InnovEnergy.App.Backend.Database; using InnovEnergy.App.Backend.Relations; @@ -37,7 +36,7 @@ public static class SessionMethods return user is not null && folder is not null && user.HasWriteAccess - && user.HasAccessTo(folder) // TODO: && user.HasAccessTo(folder.Parent()) ??? + && user.HasAccessTo(folder) && Db.Delete(folder); } @@ -46,12 +45,14 @@ public static class SessionMethods { var user = session?.User; + //Note: keep generation of access _after_ generation of object to prevent "zombie" access-rights. + return user is not null && installation is not null && user.HasWriteAccess && user.HasAccessTo(installation.Parent()) && Db.Create(installation) - && InstallationMethods.CreateBucket(installation).Result + && installation.CreateBucket().Result && Db.Create(new InstallationAccess { UserId = user.Id, InstallationId = installation.Id }); } @@ -75,7 +76,7 @@ public static class SessionMethods return user is not null && installation is not null && user.HasWriteAccess - && user.HasAccessTo(installation) // TODO: && user.HasAccessTo(installation.Parent()) ??? + && user.HasAccessTo(installation) && Db.Delete(installation); } diff --git a/csharp/App/Backend/DataTypes/Methods/User.cs b/csharp/App/Backend/DataTypes/Methods/User.cs index 97eb4d10a..d64e2e84b 100644 --- a/csharp/App/Backend/DataTypes/Methods/User.cs +++ b/csharp/App/Backend/DataTypes/Methods/User.cs @@ -180,10 +180,8 @@ public static class UserMethods return $"{user.Id}InnovEnergy"; } - - - - // TODO + + // TODO? private static Boolean IsValidEmail(String email) { try diff --git a/csharp/App/Backend/Database/Create.cs b/csharp/App/Backend/Database/Create.cs index 537192476..d1b6d8318 100644 --- a/csharp/App/Backend/Database/Create.cs +++ b/csharp/App/Backend/Database/Create.cs @@ -21,7 +21,7 @@ public static partial class Db public static Boolean Create(User user) { - if (GetUserByEmail(user.Email) is not null) // TODO: User unique by username instead of email? + if (GetUserByEmail(user.Email) is not null) return false; user.Password = user.SaltAndHashPassword(user.Password); From 4a19ebd49cf32d4db7eaf6b14bc0d14a29468a0e Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 16 Mar 2023 16:53:36 +0100 Subject: [PATCH 5/6] various small comments --- csharp/App/Backend/DataTypes/Methods/User.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/csharp/App/Backend/DataTypes/Methods/User.cs b/csharp/App/Backend/DataTypes/Methods/User.cs index d64e2e84b..83905a911 100644 --- a/csharp/App/Backend/DataTypes/Methods/User.cs +++ b/csharp/App/Backend/DataTypes/Methods/User.cs @@ -31,7 +31,8 @@ public static class UserMethods .Distinct(); // Distinct because the user might have direct access - // to a child folder of a folder he has already access to + // to a child folder of a folder he has already access to + // ---TODO shouldn't we prevent doubling permissions? -K" } public static IEnumerable AccessibleFoldersAndInstallations(this User user) From 44e183a9f1370b7ecbb593d9feae73bb55de8add Mon Sep 17 00:00:00 2001 From: ig Date: Fri, 17 Mar 2023 09:11:26 +0100 Subject: [PATCH 6/6] Fix AccessibleFolders --- csharp/App/Backend/DataTypes/Methods/Folder.cs | 2 +- csharp/App/Backend/DataTypes/Methods/User.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/csharp/App/Backend/DataTypes/Methods/Folder.cs b/csharp/App/Backend/DataTypes/Methods/Folder.cs index b6543e53e..404410997 100644 --- a/csharp/App/Backend/DataTypes/Methods/Folder.cs +++ b/csharp/App/Backend/DataTypes/Methods/Folder.cs @@ -74,7 +74,7 @@ public static class FolderMethods public static Boolean IsRelativeRoot(this Folder folder) { - return folder.ParentId < 0; // root has ParentId 0 by definition + return folder.ParentId < 0; } public static Boolean WasMoved(this Folder folder) diff --git a/csharp/App/Backend/DataTypes/Methods/User.cs b/csharp/App/Backend/DataTypes/Methods/User.cs index 83905a911..f0d2c347f 100644 --- a/csharp/App/Backend/DataTypes/Methods/User.cs +++ b/csharp/App/Backend/DataTypes/Methods/User.cs @@ -27,7 +27,7 @@ public static class UserMethods { return user .DirectlyAccessibleFolders() - .SelectMany(f => f.DescendantFolders()) + .SelectMany(f => f.DescendantFolders().Prepend(f)) .Distinct(); // Distinct because the user might have direct access @@ -51,7 +51,7 @@ public static class UserMethods .Select(r => r.InstallationId) .Select(Db.GetInstallationById) .NotNull() - .Do(i => i.ParentId = -1); // hide inaccessible parents from calling user + .Do(i => i.ParentId = 0); // hide inaccessible parents from calling user } public static IEnumerable DirectlyAccessibleFolders(this User user) @@ -62,7 +62,7 @@ public static class UserMethods .Select(r => r.FolderId) .Select(Db.GetFolderById) .NotNull() - .Do(i => i.ParentId = -1); // hide inaccessible parents from calling user; + .Do(i => i.ParentId = 0); // hide inaccessible parents from calling user; } public static IEnumerable ChildUsers(this User parent) @@ -172,6 +172,12 @@ public static class UserMethods .Ancestors() .Contains(user); } + + public static Boolean IsRelativeRoot(this User user, Installation i) + { + // TODO: determine not by id but by accessibility + return i.ParentId < 0; + } public static String Salt(this User user) {