Skip to content
Snippets Groups Projects
Commit f76f9f11 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Merge branch 'Hotfix/0071-fixResourceCreate' into 'master'

Fix: for live (rpdm/issues#71)

See merge request !149
parents fa03873c 7c3da250
No related branches found
No related tags found
1 merge request!149Fix: for live (rpdm/issues#71)
......@@ -19,7 +19,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db)
where tableEntry.Id == id
&& tableEntry.Deleted == true
&& tableEntry.Deleted
select tableEntry).Count() == 1;
});
}
......@@ -32,7 +32,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where expression.Invoke(tableEntry) == id
&& tableEntry.Deleted == false
&& !tableEntry.Deleted
select tableEntry).FirstOrDefault();
});
}
......@@ -61,7 +61,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where whereClause.Invoke(tableEntry)
&& tableEntry.Deleted == false
&& !tableEntry.Deleted
select tableEntry).FirstOrDefault();
});
}
......@@ -72,7 +72,7 @@ namespace Coscine.Database.Models
{
return
(from tableEntry in GetITableFromDatabase(db)
where tableEntry.Deleted == false
where !tableEntry.Deleted
select tableEntry).ToList();
});
}
......@@ -84,7 +84,7 @@ namespace Coscine.Database.Models
return
(from tableEntry in GetITableFromDatabase(db).AsExpandable()
where whereClause.Invoke(tableEntry)
&& tableEntry.Deleted == false
&& !tableEntry.Deleted
select tableEntry).ToList();
});
}
......@@ -107,18 +107,12 @@ namespace Coscine.Database.Models
public override int Delete(Project databaseObject)
{
databaseObject.Deleted = true;
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (int)db.Update(databaseObject).State;
});
return DatabaseConnection.ConnectToDatabase((db) => (int)db.Update(databaseObject).State);
}
public int HardDelete(Project databaseObject)
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (int) db.Remove(databaseObject).State;
});
return DatabaseConnection.ConnectToDatabase((db) => (int)db.Remove(databaseObject).State);
}
public int HardDelete(Expression<Func<Project, bool>> whereClause)
......@@ -177,7 +171,7 @@ namespace Coscine.Database.Models
join pi in db.ProjectInstitutes on p.Id equals pi.ProjectId into joinedPi
from jpi in joinedPi.DefaultIfEmpty()
where p.Deleted == false
where !p.Deleted
group jpi by jpi.OrganizationUrl into g
select new OrganizationCountObject(g.Key, g.Count())).ToList();
});
......@@ -189,8 +183,8 @@ namespace Coscine.Database.Models
var slug = projectObject.DisplayName;
slug = slug.ToLower();
slug = Regex.Replace(slug, @"[\s-]+", "-");
slug = Regex.Replace(slug, @"[^a-z0-9-]*|", "");
slug = Regex.Replace(slug, @"^-|-$", "");
slug = Regex.Replace(slug, "[^a-z0-9-]*|", "");
slug = Regex.Replace(slug, "^-|-$", "");
Random r = new Random();
int rInt = r.Next(0, 9000000) + 1000000;
......@@ -211,7 +205,7 @@ namespace Coscine.Database.Models
while (GetBySlug(fullSlug + rInt) != null)
{
rInt++;
};
}
fullSlug += rInt;
}
......@@ -333,11 +327,11 @@ namespace Coscine.Database.Models
public IEnumerable<Project> GetTopLevelWithAccess(User user, params string[] allowedAccess)
{
return GetWithAccess(user, allowedAccess, (allowedProjectIds) => GetAllWhere((project) =>
return GetWithAccess(user, allowedAccess, (_) => GetAllWhere((project) =>
(
// all accessable projects that have no parents
(!project.SubProjectSubProjectNavigations.Any())
|| // all accessable projects that have no accessable parents
// all accessible projects that have no parents
(project.SubProjectSubProjectNavigations.Count == 0)
|| // all accessible projects that have no accessible parents
(
project.SubProjectSubProjectNavigations.All(
(parentProjects) =>
......@@ -436,7 +430,7 @@ namespace Coscine.Database.Models
{
list = GetAllWhere((dbProject) => (from subProject in dbProject.SubProjectProjects
where subProject.SubProjectId == currentProject.Id
&& subProject.Project.Deleted == false
&& !subProject.Project.Deleted
select subProject).Any());
if (list.Any())
......@@ -530,6 +524,5 @@ namespace Coscine.Database.Models
}
return $"{counted}/{maxCount}";
}
}
}
\ No newline at end of file
......@@ -25,13 +25,15 @@ namespace Coscine.Database.Models
public Dictionary<string, string> GetResourceTypeOptions(Guid id)
{
var dictionary = new Dictionary<string, string>();
var resourceType = GetById(id);
dictionary.Add("accessKey", resourceType.AccessKey);
dictionary.Add("secretKey", resourceType.SecretKey);
dictionary.Add("bucketname", resourceType.BucketName);
dictionary.Add("endpoint", resourceType.Endpoint);
dictionary.Add("size", $"{resourceType.Size}");
var dictionary = new Dictionary<string, string>
{
{ "accessKey", resourceType.AccessKey },
{ "secretKey", resourceType.SecretKey },
{ "bucketname", resourceType.BucketName },
{ "endpoint", resourceType.Endpoint },
{ "size", $"{resourceType.Size}" }
};
return dictionary;
}
}
......
......@@ -24,17 +24,19 @@ namespace Coscine.Database.Models
public Dictionary<string, string> GetResourceTypeOptions(Guid id)
{
var dictionary = new Dictionary<string, string>();
var resourceType = GetById(id);
dictionary.Add("accessKey", resourceType.AccessKey);
dictionary.Add("secretKey", resourceType.SecretKey);
dictionary.Add("accessKeyRead", resourceType.AccessKeyRead);
dictionary.Add("secretKeyRead", resourceType.SecretKeyRead);
dictionary.Add("accessKeyWrite", resourceType.AccessKeyWrite);
dictionary.Add("secretKeyWrite", resourceType.SecretKeyWrite);
dictionary.Add("bucketname", resourceType.BucketName);
dictionary.Add("endpoint", resourceType.Endpoint);
dictionary.Add("size", $"{resourceType.Size}");
var dictionary = new Dictionary<string, string>
{
{ "accessKey", resourceType.AccessKey },
{ "secretKey", resourceType.SecretKey },
{ "accessKeyRead", resourceType.AccessKeyRead },
{ "secretKeyRead", resourceType.SecretKeyRead },
{ "accessKeyWrite", resourceType.AccessKeyWrite },
{ "secretKeyWrite", resourceType.SecretKeyWrite },
{ "bucketname", resourceType.BucketName },
{ "endpoint", resourceType.Endpoint },
{ "size", $"{resourceType.Size}" }
};
return dictionary;
}
}
......
......@@ -14,6 +14,15 @@ namespace Coscine.Database.Models
public class ResourceModel : DatabaseModel<Resource>
{
private readonly IConfiguration _configuration = new ConsulConfiguration();
private static readonly Dictionary<string, string> _configs = new Dictionary<string, string>
{
{ "rds", "coscine/global/rds/ecs-rwth/rds" },
{ "rdsude", "coscine/global/rds/ecs-ude/rds" },
{ "rdss3", "coscine/global/rds/ecs-rwth/rds-s3" },
{ "rdss3ude", "coscine/global/rds/ecs-ude/rds-s3" }
};
public Resource StoreFromObject(ResourceObject resourceObject)
{
if (!resourceObject.Disciplines.Any() || resourceObject.ResourceTypeOption == null)
......@@ -48,7 +57,7 @@ namespace Coscine.Database.Models
}
catch (Exception)
{
// Makes sure to delete all FK refrences, otherwise a delete is not possible
// Makes sure to delete all FK references, otherwise a delete is not possible
DeleteResource(resource);
throw;
}
......@@ -100,7 +109,7 @@ namespace Coscine.Database.Models
join rt in db.ResourceTypes on r.TypeId equals rt.Id into joinedRt
from jrt in joinedRt.DefaultIfEmpty()
where jp.Deleted == false &&
where !jp.Deleted &&
IsLikeRds(jrt.DisplayName)
group r by jpi.OrganizationUrl into g
select new OrganizationResourceListObject(g.Key, g.ToList())).ToList();
......@@ -120,13 +129,14 @@ namespace Coscine.Database.Models
}
else
{
var prefix = _configs[resource.Type.DisplayName];
RdsresourceType rdsResourceType = new RdsresourceType()
{
BucketName = resource.Id.ToString(),
Size = rdsResourceTypeObject.Size,
AccessKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds/object_user_name"),
SecretKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds/object_user_secretkey"),
Endpoint = _configuration.GetString("coscine/global/rds/ecs-rwth/rds/s3_endpoint"),
AccessKey = _configuration.GetString($"{prefix}/object_user_name"),
SecretKey = _configuration.GetString($"{prefix}/object_user_secretkey"),
Endpoint = _configuration.GetString($"{prefix}/s3_endpoint"),
};
rdsResourceTypeModel.Insert(rdsResourceType);
resource.ResourceTypeOptionId = rdsResourceType.Id;
......@@ -209,16 +219,17 @@ namespace Coscine.Database.Models
}
else
{
var prefix = _configs[resource.Type.DisplayName];
var rdsS3ResourceType = new RdsS3resourceType()
{
BucketName = resource.Id.ToString(),
AccessKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds-s3/object_user_name"),
SecretKey = _configuration.GetString("coscine/global/rds/ecs-rwth/rds-s3/object_user_secretkey"),
AccessKey = _configuration.GetString($"{prefix}/object_user_name"),
SecretKey = _configuration.GetString($"{prefix}/object_user_secretkey"),
AccessKeyRead = $"read_{resource.Id}",
SecretKeyRead = RandomHelper.GenerateRandomChunk(32),
AccessKeyWrite = $"write_{resource.Id}",
SecretKeyWrite = RandomHelper.GenerateRandomChunk(32),
Endpoint = _configuration.GetString("coscine/global/rds/ecs-rwth/rds-s3/s3_endpoint"),
Endpoint = _configuration.GetString($"{prefix}/s3_endpoint"),
Size = rdsS3ResourceTypeObject.Size,
};
rdsS3ResourceTypeModel.Insert(rdsS3ResourceType);
......@@ -418,7 +429,6 @@ namespace Coscine.Database.Models
LinkedResourceTypeModel linkedResourceTypeModel = new LinkedResourceTypeModel();
var linkedResourceType = linkedResourceTypeModel.GetById(resource.ResourceTypeOptionId.Value);
resourceTypeOptionObject = new LinkedResourceTypeObject(linkedResourceType.Id);
}
else if (IsLikeRdsS3(resource.Type.DisplayName) && resource.ResourceTypeOptionId != null)
{
......@@ -451,7 +461,7 @@ namespace Coscine.Database.Models
resourceTypeOptionObject == null ? new JObject() : JObject.FromObject(resourceTypeOptionObject),
resource.ApplicationProfile,
JToken.Parse(resource.FixedValues ?? "{}"),
(resource.Creator != null) ? resource.Creator : null,
resource.Creator,
resource.Archived == "1"
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment