Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Coscine
backend
libraries
Database
Commits
7c3da250
Commit
7c3da250
authored
Nov 04, 2021
by
L. Ellenbeck
Browse files
Fix: for live (rpdm/issues#71)
parent
23e642ff
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/Database/Models/ProjectModel.cs
View file @
7c3da250
...
...
@@ -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
)
...
...
@@ -126,8 +120,8 @@ namespace Coscine.Database.Models
return
DatabaseConnection
.
ConnectToDatabase
((
db
)
=>
{
return
(
int
)
db
.
Remove
(
from
tableEntry
in
GetITableFromDatabase
(
db
).
AsExpandable
()
where
whereClause
.
Invoke
(
tableEntry
)
select
tableEntry
).
State
;
where
whereClause
.
Invoke
(
tableEntry
)
select
tableEntry
).
State
;
});
}
...
...
@@ -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 access
a
ble projects that have no parents
(
!
project
.
SubProjectSubProjectNavigations
.
Any
()
)
||
// all access
a
ble projects that have no access
a
ble parents
// all access
i
ble projects that have no parents
(
project
.
SubProjectSubProjectNavigations
.
Count
==
0
)
||
// all access
i
ble projects that have no access
i
ble 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
src/Database/Models/RDSResourceTypeModel.cs
View file @
7c3da250
...
...
@@ -25,14 +25,16 @@ 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
;
}
}
}
}
\ No newline at end of file
src/Database/Models/RdsS3ResourceTypeModel.cs
View file @
7c3da250
...
...
@@ -24,18 +24,20 @@ 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
;
}
}
}
}
\ No newline at end of file
src/Database/Models/ResourceModel.cs
View file @
7c3da250
...
...
@@ -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 ref
e
rences, 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"
);
}
...
...
@@ -549,4 +559,4 @@ namespace Coscine.Database.Models
return
compare
==
"rdss3"
||
compare
==
"rdss3ude"
;
}
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment