renamed user2folder and user2installation, reimplemented getbyId
This commit is contained in:
parent
787b02f97e
commit
0f7daea8ea
|
@ -46,58 +46,58 @@ public class Controller
|
|||
}
|
||||
|
||||
|
||||
// [Returns<User>]
|
||||
// [Returns(HttpStatusCode.Unauthorized)]
|
||||
// [HttpGet($"{nameof(GetUserById)}")]
|
||||
// public Object GetUserById(Int64 id)
|
||||
// {
|
||||
// var caller = GetCaller();
|
||||
// if (caller is null)
|
||||
// return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
//
|
||||
// var user = Db.GetUserById(id);
|
||||
//
|
||||
// if (user is null || !caller.HasAccessTo(user))
|
||||
// return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
//
|
||||
// return user;
|
||||
// }
|
||||
|
||||
//
|
||||
// [Returns<Installation>]
|
||||
// [Returns(HttpStatusCode.Unauthorized)]
|
||||
// [HttpGet($"{nameof(GetInstallationById)}")]
|
||||
// public Object GetInstallationById(Int64 id)
|
||||
// {
|
||||
// var caller = GetCaller();
|
||||
// if (caller == null)
|
||||
// return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
//
|
||||
// var installation = Db.GetInstallationById(id);
|
||||
//
|
||||
// if (installation is null || !caller.HasAccessTo(installation))
|
||||
// return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
//
|
||||
// return installation;
|
||||
// }
|
||||
[Returns<User>]
|
||||
[Returns(Unauthorized)]
|
||||
[HttpGet($"{nameof(GetUserById)}")]
|
||||
public Object GetUserById(Int64 id)
|
||||
{
|
||||
var caller = GetSession()?.User;
|
||||
if (caller == null)
|
||||
return _Unauthorized;
|
||||
|
||||
var user = Db.GetUserById(id);
|
||||
|
||||
if (user is null || !caller.HasAccessTo(user))
|
||||
return _Unauthorized;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
// [Returns<Folder>]
|
||||
// [Returns(HttpStatusCode.Unauthorized)]
|
||||
// [HttpGet($"{nameof(GetFolderById)}")]
|
||||
// public Object GetFolderById(Int64 id)
|
||||
// {
|
||||
// var caller = GetCaller();
|
||||
// if (caller == null)
|
||||
// return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
//
|
||||
// var folder = Db.GetFolderById(id);
|
||||
//
|
||||
// if (folder is null || !caller.HasAccessTo(folder))
|
||||
// return new HttpResponseMessage(HttpStatusCode.Unauthorized);
|
||||
//
|
||||
// return folder;
|
||||
// }
|
||||
[Returns<Installation>]
|
||||
[Returns(Unauthorized)]
|
||||
[HttpGet($"{nameof(GetInstallationById)}")]
|
||||
public Object GetInstallationById(Int64 id)
|
||||
{
|
||||
var user = GetSession()?.User;
|
||||
if (user == null)
|
||||
return _Unauthorized;
|
||||
|
||||
var installation = Db.GetInstallationById(id);
|
||||
|
||||
if (installation is null || !user.HasAccessTo(installation))
|
||||
return _Unauthorized;
|
||||
|
||||
return installation;
|
||||
}
|
||||
|
||||
|
||||
[Returns<Folder>]
|
||||
[Returns(Unauthorized)]
|
||||
[HttpGet($"{nameof(GetFolderById)}")]
|
||||
public Object GetFolderById(Int64 id)
|
||||
{
|
||||
var user = GetSession()?.User;
|
||||
if (user == null)
|
||||
return _Unauthorized;
|
||||
|
||||
var folder = Db.GetFolderById(id);
|
||||
|
||||
if (folder is null || !user.HasAccessTo(folder))
|
||||
return _Unauthorized;
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
[Returns<Installation[]>] // assuming swagger knows about arrays but not lists (JSON)
|
||||
|
|
|
@ -16,10 +16,11 @@ public static class InstallationMethods
|
|||
{
|
||||
//secret 55MAqyO_FqUmh7O64VIO0egq50ERn_WIAWuc2QC44QU
|
||||
const String apiKey = "EXO44d2979c8e570eae81ead564";
|
||||
const String salt = "3e5b3069-214a-43ee-8d85-57d72000c19d";
|
||||
|
||||
var cmd = Cli
|
||||
.Wrap("s3cmd")
|
||||
.WithArguments(new[] { "signurl",$"s3://{installation.Name.Replace(" ", "-")}", validity.TotalSeconds.ToString(), "--access_key", apiKey});
|
||||
.WithArguments(new[] { "signurl",$"s3://{installation.Id}-{salt}", validity.TotalSeconds.ToString(), "--access_key", apiKey});
|
||||
|
||||
var x = await cmd.ExecuteBufferedAsync();
|
||||
installation.S3Url = x.StandardOutput.Replace("\n", "").Replace(" ", "");
|
||||
|
|
|
@ -45,7 +45,7 @@ public static class UserMethods
|
|||
public static IEnumerable<Installation> DirectlyAccessibleInstallations(this User user)
|
||||
{
|
||||
return Db
|
||||
.User2Installation
|
||||
.InstallationAccess
|
||||
.Where(r => r.UserId == user.Id)
|
||||
.Select(r => r.InstallationId)
|
||||
.Select(Db.GetInstallationById)
|
||||
|
@ -56,7 +56,7 @@ public static class UserMethods
|
|||
public static IEnumerable<Folder> DirectlyAccessibleFolders(this User user)
|
||||
{
|
||||
return Db
|
||||
.User2Folder
|
||||
.FolderAccess
|
||||
.Where(r => r.UserId == user.Id)
|
||||
.Select(r => r.FolderId)
|
||||
.Select(Db.GetFolderById)
|
||||
|
@ -125,7 +125,7 @@ public static class UserMethods
|
|||
public static Boolean HasDirectAccessTo(this User user, Folder folder)
|
||||
{
|
||||
return Db
|
||||
.User2Folder
|
||||
.FolderAccess
|
||||
.Any(r => r.FolderId == folder.Id && r.UserId == user.Id);
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public static class UserMethods
|
|||
public static Boolean HasDirectAccessTo(this User user, Installation installation)
|
||||
{
|
||||
return Db
|
||||
.User2Installation
|
||||
.InstallationAccess
|
||||
.Any(r => r.UserId == user.Id && r.InstallationId == installation.Id);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ public static partial class Db
|
|||
public static TableQuery<Folder> Folders => Connection.Table<Folder>();
|
||||
public static TableQuery<Installation> Installations => Connection.Table<Installation>();
|
||||
public static TableQuery<User> Users => Connection.Table<User>();
|
||||
public static TableQuery<FolderAccess> User2Folder => Connection.Table<FolderAccess>();
|
||||
public static TableQuery<InstallationAccess> User2Installation => Connection.Table<InstallationAccess>();
|
||||
public static TableQuery<FolderAccess> FolderAccess => Connection.Table<FolderAccess>();
|
||||
public static TableQuery<InstallationAccess> InstallationAccess => Connection.Table<InstallationAccess>();
|
||||
|
||||
|
||||
static Db()
|
||||
|
|
|
@ -21,7 +21,7 @@ public static partial class Db
|
|||
|
||||
Boolean DeleteDescendantFolderAndItsDependencies(Folder f)
|
||||
{
|
||||
User2Folder .Delete(r => r.FolderId == f.Id);
|
||||
FolderAccess .Delete(r => r.FolderId == f.Id);
|
||||
Installations.Delete(r => r.ParentId == f.Id);
|
||||
|
||||
return Folders.Delete(r => r.Id == f.Id) > 0;
|
||||
|
@ -34,7 +34,7 @@ public static partial class Db
|
|||
|
||||
Boolean DeleteInstallationAndItsDependencies()
|
||||
{
|
||||
User2Installation.Delete(i => i.InstallationId == installation.Id);
|
||||
InstallationAccess.Delete(i => i.InstallationId == installation.Id);
|
||||
return Installations.Delete(i => i.Id == installation.Id) > 0;
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public static partial class Db
|
|||
|
||||
Boolean DeleteUserAndHisDependencies()
|
||||
{
|
||||
User2Folder .Delete(u => u.UserId == user.Id);
|
||||
User2Installation.Delete(u => u.UserId == user.Id);
|
||||
FolderAccess .Delete(u => u.UserId == user.Id);
|
||||
InstallationAccess.Delete(u => u.UserId == user.Id);
|
||||
|
||||
return Users.Delete(u => u.Id == user.Id) > 0;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public static partial class Db
|
|||
|
||||
private static void GiveFakeUsersAccessToFolders()
|
||||
{
|
||||
foreach (var uf in User2Folder) // remove existing relations
|
||||
foreach (var uf in FolderAccess) // remove existing relations
|
||||
Connection.Delete(uf);
|
||||
|
||||
var nFolders = Folders.Count();
|
||||
|
@ -81,7 +81,7 @@ public static partial class Db
|
|||
|
||||
private static void GiveFakeUsersAccessToInstallations()
|
||||
{
|
||||
foreach (var ui in User2Installation) // remove existing relations
|
||||
foreach (var ui in InstallationAccess) // remove existing relations
|
||||
Connection.Delete(ui);
|
||||
|
||||
var nbInstallations = Installations.Count();
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue