Skip to content

Commit 10c870b

Browse files
authored
Enable 3rd party sharing consent in config (#814)
1 parent d92adf6 commit 10c870b

File tree

8 files changed

+57
-24
lines changed

8 files changed

+57
-24
lines changed

mwdb/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@ def require_auth():
221221
api.add_resource(ObjectResource, "/object")
222222
api.add_resource(ObjectItemResource, "/object/<hash64:identifier>")
223223
api.add_resource(ObjectFavoriteResource, "/object/<hash64:identifier>/favorite")
224-
api.add_resource(
225-
ObjectShare3rdPartyResource, "/object/<hash64:identifier>/share_3rd_party"
226-
)
224+
225+
if app_config.mwdb.enable_3rd_party_sharing_consent:
226+
api.add_resource(
227+
ObjectShare3rdPartyResource, "/object/<hash64:identifier>/share_3rd_party"
228+
)
227229

228230
# Count endpoint
229231
api.add_resource(ObjectCountResource, "/<any(file, config, blob, object):type>/count")

mwdb/core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class MWDBConfig(Config):
118118
enable_hooks = key(cast=intbool, required=False, default=True)
119119
enable_karton = key(cast=intbool, required=False, default=False)
120120
enable_oidc = key(cast=intbool, required=False, default=False)
121+
enable_3rd_party_sharing_consent = key(cast=intbool, required=False, default=False)
121122

122123
mail_smtp = key(cast=str, required=False)
123124
mail_from = key(cast=str, required=False, default="noreply@mwdb")

mwdb/resources/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def get(self):
6464
"is_registration_enabled": app_config.mwdb.enable_registration,
6565
"is_karton_enabled": app_config.mwdb.enable_karton,
6666
"is_oidc_enabled": app_config.mwdb.enable_oidc,
67+
"is_3rd_party_sharing_consent_enabled": (
68+
app_config.mwdb.enable_3rd_party_sharing_consent
69+
),
6770
"recaptcha_site_key": app_config.mwdb.recaptcha_site_key,
6871
"request_timeout": app_config.mwdb.request_timeout,
6972
"file_upload_timeout": app_config.mwdb.file_upload_timeout,

mwdb/schema/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class ServerInfoResponseSchema(Schema):
1313
is_registration_enabled = fields.Boolean(required=True, allow_none=False)
1414
is_karton_enabled = fields.Boolean(required=True, allow_none=False)
1515
is_oidc_enabled = fields.Boolean(required=True, allow_none=False)
16+
is_3rd_party_sharing_consent_enabled = fields.Boolean(
17+
required=True, allow_none=False
18+
)
1619
recaptcha_site_key = fields.Str(required=True, allow_none=True)
1720
request_timeout = fields.Int(required=True, allow_none=False)
1821
file_upload_timeout = fields.Int(required=True, allow_none=False)

mwdb/web/src/components/ShowObject/ShowObject.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,18 @@ export default function ShowObject({
126126
</Extendable>
127127
</div>
128128
<AttributesBox />
129-
<Share3rdPartyBox
130-
isEnabled={objectState.object.share_3rd_party}
131-
objectId={objectState.object.id}
132-
/>
129+
{config.config[
130+
"is_3rd_party_sharing_consent_enabled"
131+
] ? (
132+
<Share3rdPartyBox
133+
isEnabled={
134+
objectState.object.share_3rd_party
135+
}
136+
objectId={objectState.object.id}
137+
/>
138+
) : (
139+
[]
140+
)}
133141
</Extendable>
134142
</div>
135143
<div className="col-md-5">

mwdb/web/src/components/Upload.jsx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AuthContext, Capability } from "@mwdb-web/commons/auth";
1212
import {
1313
Autocomplete,
1414
DataTable,
15+
ShowIf,
1516
View,
1617
getErrorMessage,
1718
} from "@mwdb-web/commons/ui";
@@ -303,24 +304,32 @@ export default function Upload() {
303304
) : (
304305
[]
305306
)}
306-
<div className="form-group">
307-
<div className="material-switch make-horizontal">
308-
<input
309-
type="checkbox"
310-
name="share_3rd"
311-
id="share_3rd_party"
312-
checked={share3rdParty}
313-
onChange={() =>
314-
setShare3rdParty(!share3rdParty)
315-
}
316-
/>
317-
<label
318-
htmlFor="share_3rd_party"
319-
className="bg-primary"
320-
/>
307+
<ShowIf
308+
condition={
309+
config.config[
310+
"is_3rd_party_sharing_consent_enabled"
311+
]
312+
}
313+
>
314+
<div className="form-group">
315+
<div className="material-switch make-horizontal">
316+
<input
317+
type="checkbox"
318+
name="share_3rd"
319+
id="share_3rd_party"
320+
checked={share3rdParty}
321+
onChange={() =>
322+
setShare3rdParty(!share3rdParty)
323+
}
324+
/>
325+
<label
326+
htmlFor="share_3rd_party"
327+
className="bg-primary"
328+
/>
329+
</div>
330+
<label>&nbsp; Share with third parties</label>
321331
</div>
322-
<label>&nbsp; Share with third parties</label>
323-
</div>
332+
</ShowIf>
324333
<input
325334
value="Upload File"
326335
className="btn btn-success"

mwdb/web/src/types/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type ServerInfoResponse = Response<{
2828
is_registration_enabled: boolean;
2929
is_karton_enabled: boolean;
3030
is_oidc_enabled: boolean;
31+
is_3rd_party_sharing_consent_enabled: boolean;
3132
recaptcha_site_key: boolean;
3233
request_timeout: number;
3334
file_upload_timeout: number;

tests/backend/test_sharing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .relations import *
22
from .utils import ShouldRaise, MwdbTest
33
from .utils import base62uuid
4+
import pytest
45

56
def test_share_with_foreign(admin_session):
67
testCase = RelationTestCase(admin_session)
@@ -132,6 +133,11 @@ def test_list_groups_for_share(admin_session):
132133

133134

134135
def test_3rd_party_share(admin_session):
136+
# check if test_3rd_party_share is enabled
137+
resp = admin_session.request("get", "/server")
138+
if not resp.get("is_3rd_party_sharing_consent_enabled", False):
139+
pytest.skip("Sharing with 3rd parties consent is disabled")
140+
135141
testCase = RelationTestCase(admin_session)
136142

137143
Alice = testCase.new_user("Alice")

0 commit comments

Comments
 (0)