Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
3f2099c2
Verified
Commit
3f2099c2
authored
4 months ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
WIP: mypy
parent
e00a4a2e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!175
BUG: Request responses without the "Set-Cookie" header no longer overwrite the...
,
!164
Fix mypy errors
Pipeline
#58012
failed
4 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/linkahead/apiutils.py
+8
-5
8 additions, 5 deletions
src/linkahead/apiutils.py
src/linkahead/common/administration.py
+25
-10
25 additions, 10 deletions
src/linkahead/common/administration.py
src/linkahead/utils/plantuml.py
+5
-4
5 additions, 4 deletions
src/linkahead/utils/plantuml.py
with
38 additions
and
19 deletions
src/linkahead/apiutils.py
+
8
−
5
View file @
3f2099c2
...
...
@@ -275,9 +275,11 @@ def compare_entities(entity0: Optional[Entity] = None,
if
entity1
is
not
None
:
raise
ValueError
(
"
You cannot use both entity1 and new_entity
"
)
entity1
=
new_entity
assert
entity0
is
not
None
assert
entity1
is
not
None
diff
:
tuple
=
({
"
properties
"
:
{},
"
parents
"
:
[]},
{
"
properties
"
:
{},
"
parents
"
:
[]})
diff
:
tuple
[
dict
[
str
,
Any
],
dict
[
str
,
Any
]]
=
({
"
properties
"
:
{},
"
parents
"
:
[]},
{
"
properties
"
:
{},
"
parents
"
:
[]})
if
entity0
is
entity1
:
return
diff
...
...
@@ -550,9 +552,10 @@ def merge_entities(entity_a: Entity,
"""
# Compare both entities:
diff_r1
,
diff_r2
=
compare_entities
(
entity_a
,
entity_b
,
entity_name_id_equivalency
=
merge_id_with_resolved_entity
,
compare_referenced_records
=
merge_references_with_empty_diffs
)
diff_r1
,
diff_r2
=
compare_entities
(
entity_a
,
entity_b
,
entity_name_id_equivalency
=
merge_id_with_resolved_entity
,
compare_referenced_records
=
merge_references_with_empty_diffs
)
# Go through the comparison and try to apply changes to entity_a:
for
key
in
diff_r2
[
"
parents
"
]:
...
...
This diff is collapsed.
Click to expand it.
src/linkahead/common/administration.py
+
25
−
10
View file @
3f2099c2
...
...
@@ -91,7 +91,7 @@ def get_server_properties() -> dict[str, Optional[str]]:
props
:
dict
[
str
,
Optional
[
str
]]
=
dict
()
for
elem
in
xml
.
getroot
():
props
[
elem
.
tag
]
=
elem
.
text
props
[
elem
.
tag
]
=
str
(
elem
.
text
)
return
props
...
...
@@ -156,7 +156,10 @@ def generate_password(length: int):
def
_retrieve_user
(
name
:
str
,
realm
:
Optional
[
str
]
=
None
,
**
kwargs
):
con
=
get_connection
()
try
:
return
con
.
_http_request
(
method
=
"
GET
"
,
path
=
"
User/
"
+
(
realm
+
"
/
"
+
name
if
realm
is
not
None
else
name
),
**
kwargs
).
read
()
return
con
.
_http_request
(
method
=
"
GET
"
,
path
=
"
User/
"
+
(
realm
+
"
/
"
+
name
if
realm
is
not
None
else
name
),
**
kwargs
).
read
()
except
HTTPForbiddenError
as
e
:
e
.
msg
=
"
You are not permitted to retrieve this user.
"
raise
...
...
@@ -198,7 +201,9 @@ def _update_user(name: str,
if
entity
is
not
None
:
params
[
"
entity
"
]
=
str
(
entity
)
try
:
return
con
.
put_form_data
(
entity_uri_segment
=
"
User/
"
+
(
realm
+
"
/
"
+
name
if
realm
is
not
None
else
name
),
params
=
params
,
**
kwargs
).
read
()
return
con
.
put_form_data
(
entity_uri_segment
=
"
User/
"
+
(
realm
+
"
/
"
+
name
if
realm
is
not
None
else
name
),
params
=
params
,
**
kwargs
).
read
()
except
HTTPResourceNotFoundError
as
e
:
e
.
msg
=
"
User does not exist.
"
raise
e
...
...
@@ -246,7 +251,9 @@ def _insert_user(name: str,
def
_insert_role
(
name
,
description
,
**
kwargs
):
con
=
get_connection
()
try
:
return
con
.
post_form_data
(
entity_uri_segment
=
"
Role
"
,
params
=
{
"
role_name
"
:
name
,
"
role_description
"
:
description
},
**
kwargs
).
read
()
return
con
.
post_form_data
(
entity_uri_segment
=
"
Role
"
,
params
=
{
"
role_name
"
:
name
,
"
role_description
"
:
description
},
**
kwargs
).
read
()
except
HTTPForbiddenError
as
e
:
e
.
msg
=
"
You are not permitted to insert a new role.
"
raise
...
...
@@ -259,7 +266,9 @@ def _insert_role(name, description, **kwargs):
def
_update_role
(
name
,
description
,
**
kwargs
):
con
=
get_connection
()
try
:
return
con
.
put_form_data
(
entity_uri_segment
=
"
Role/
"
+
name
,
params
=
{
"
role_description
"
:
description
},
**
kwargs
).
read
()
return
con
.
put_form_data
(
entity_uri_segment
=
"
Role/
"
+
name
,
params
=
{
"
role_description
"
:
description
},
**
kwargs
).
read
()
except
HTTPForbiddenError
as
e
:
e
.
msg
=
"
You are not permitted to update this role.
"
raise
...
...
@@ -301,8 +310,10 @@ def _set_roles(username, roles, realm=None, **kwargs):
body
=
xml2str
(
xml
)
con
=
get_connection
()
try
:
body
=
con
.
_http_request
(
method
=
"
PUT
"
,
path
=
"
UserRoles/
"
+
(
realm
+
"
/
"
+
username
if
realm
is
not
None
else
username
),
body
=
body
,
**
kwargs
).
read
()
body
=
con
.
_http_request
(
method
=
"
PUT
"
,
path
=
"
UserRoles/
"
+
(
realm
+
"
/
"
+
username
if
realm
is
not
None
else
username
),
body
=
body
,
**
kwargs
).
read
()
except
HTTPForbiddenError
as
e
:
e
.
msg
=
"
You are not permitted to set this user
'
s roles.
"
raise
...
...
@@ -369,7 +380,8 @@ def _set_permissions(role, permission_rules, **kwargs):
body
=
xml2str
(
xml
)
con
=
get_connection
()
try
:
return
con
.
_http_request
(
method
=
"
PUT
"
,
path
=
"
PermissionRules/
"
+
role
,
body
=
body
,
**
kwargs
).
read
()
return
con
.
_http_request
(
method
=
"
PUT
"
,
path
=
"
PermissionRules/
"
+
role
,
body
=
body
,
**
kwargs
).
read
()
except
HTTPForbiddenError
as
e
:
e
.
msg
=
"
You are not permitted to set this role
'
s permissions.
"
raise
...
...
@@ -381,7 +393,9 @@ def _set_permissions(role, permission_rules, **kwargs):
def
_get_permissions
(
role
,
**
kwargs
):
con
=
get_connection
()
try
:
return
PermissionRule
.
_parse_body
(
con
.
_http_request
(
method
=
"
GET
"
,
path
=
"
PermissionRules/
"
+
role
,
**
kwargs
).
read
())
return
PermissionRule
.
_parse_body
(
con
.
_http_request
(
method
=
"
GET
"
,
path
=
"
PermissionRules/
"
+
role
,
**
kwargs
).
read
())
except
HTTPForbiddenError
as
e
:
e
.
msg
=
"
You are not permitted to retrieve this role
'
s permissions.
"
raise
...
...
@@ -429,7 +443,8 @@ class PermissionRule():
if
permission
is
None
:
raise
ValueError
(
f
"
Permission is missing in PermissionRule xml:
{
elem
}
"
)
priority
=
PermissionRule
.
_parse_boolean
(
elem
.
get
(
"
priority
"
))
return
PermissionRule
(
elem
.
tag
,
permission
,
priority
if
priority
is
not
None
else
False
)
return
PermissionRule
(
str
(
elem
.
tag
),
permission
,
priority
if
priority
is
not
None
else
False
)
@staticmethod
def
_parse_body
(
body
:
str
):
...
...
This diff is collapsed.
Click to expand it.
src/linkahead/utils/plantuml.py
+
5
−
4
View file @
3f2099c2
...
...
@@ -130,9 +130,9 @@ def recordtypes_to_plantuml_string(iterable,
classes
=
[
el
for
el
in
iterable
if
isinstance
(
el
,
db
.
RecordType
)]
dependencies
=
{}
inheritances
=
{}
properties
=
[
p
for
p
in
iterable
if
isinstance
(
p
,
db
.
Property
)]
dependencies
:
dict
=
{}
inheritances
:
dict
=
{}
properties
:
list
=
[
p
for
p
in
iterable
if
isinstance
(
p
,
db
.
Property
)]
grouped
=
[
g
for
g
in
iterable
if
isinstance
(
g
,
Grouped
)]
def
_add_properties
(
c
,
importance
=
None
):
...
...
@@ -272,7 +272,8 @@ package \"The property P references an instance of D\" <<Rectangle>> {
return
result
def
retrieve_substructure
(
start_record_types
,
depth
,
result_id_set
=
None
,
result_container
=
None
,
cleanup
=
True
):
def
retrieve_substructure
(
start_record_types
,
depth
,
result_id_set
=
None
,
result_container
=
None
,
cleanup
=
True
):
"""
Recursively retrieves LinkAhead record types and properties, starting
from given initial types up to a specific depth.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment