Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions resources/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,11 @@ type Molecule {
v2: MoleculeV2!
}

input MoleculeAccessLevelRuleInput {
ipnftUid: String!
accessLevels: [String!]!
}

type MoleculeActivityAnnouncementV2 {
announcement: MoleculeAnnouncementEntry!
}
Expand Down Expand Up @@ -3272,6 +3277,7 @@ input MoleculeAnnouncementsFilters {
byTags: [String!]
byCategories: [String!]
byAccessLevels: [String!]
byAccessLevelRules: [MoleculeAccessLevelRuleInput!]
}

type MoleculeDataRoom {
Expand All @@ -3287,6 +3293,7 @@ input MoleculeDataRoomEntriesFilters {
byTags: [String!]
byCategories: [String!]
byAccessLevels: [String!]
byAccessLevelRules: [MoleculeAccessLevelRuleInput!]
}

type MoleculeDataRoomEntry {
Expand Down Expand Up @@ -3569,6 +3576,7 @@ input MoleculeProjectActivityFilters {
byTags: [String!]
byCategories: [String!]
byAccessLevels: [String!]
byAccessLevelRules: [MoleculeAccessLevelRuleInput!]
byKinds: [MoleculeActivityKindInput!]
}

Expand Down Expand Up @@ -3786,6 +3794,7 @@ input MoleculeSemanticSearchFilters {
byTags: [String!]
byCategories: [String!]
byAccessLevels: [String!]
byAccessLevelRules: [MoleculeAccessLevelRuleInput!]
byKinds: [MoleculeSearchEntityKindInput!]
}

Expand Down
2 changes: 2 additions & 0 deletions src/adapter/graphql/src/queries/molecule/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

mod molecule_access_filters;
mod molecule_activity_event_v2;
mod molecule_announcements_dataset_v2;
mod molecule_data_room_dataset_v2;
Expand All @@ -16,6 +17,7 @@ mod molecule_scalars_v2;
mod molecule_v2;
mod molecule_versioned_file;

pub use molecule_access_filters::*;
pub use molecule_activity_event_v2::*;
pub use molecule_announcements_dataset_v2::*;
pub use molecule_data_room_dataset_v2::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Kamu Data, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use crate::prelude::*;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(InputObject, Clone)]
pub struct MoleculeAccessLevelRuleInput {
pub ipnft_uid: String,
pub access_levels: Vec<String>,
}

impl From<MoleculeAccessLevelRuleInput> for kamu_molecule_domain::MoleculeAccessLevelRule {
fn from(value: MoleculeAccessLevelRuleInput) -> Self {
Self {
ipnft_uid: Some(value.ipnft_uid),
access_levels: value.access_levels,
}
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::prelude::*;
use crate::queries::Dataset;
use crate::queries::molecule::v2::{
MoleculeAccessLevel,
MoleculeAccessLevelRuleInput,
MoleculeAnnouncementId,
MoleculeCategory,
MoleculeChangeBy,
Expand Down Expand Up @@ -248,6 +249,7 @@ pub struct MoleculeAnnouncementsFilters {
by_tags: Option<Vec<MoleculeTag>>,
by_categories: Option<Vec<MoleculeCategory>>,
by_access_levels: Option<Vec<MoleculeAccessLevel>>,
by_access_level_rules: Option<Vec<MoleculeAccessLevelRuleInput>>,
}

impl From<MoleculeAnnouncementsFilters> for kamu_molecule_domain::MoleculeAnnouncementsFilters {
Expand All @@ -256,6 +258,9 @@ impl From<MoleculeAnnouncementsFilters> for kamu_molecule_domain::MoleculeAnnoun
by_tags: value.by_tags,
by_categories: value.by_categories,
by_access_levels: value.by_access_levels,
by_access_level_rules: value
.by_access_level_rules
.map(|rules| rules.into_iter().map(Into::into).collect()),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::prelude::*;
use crate::queries::Dataset;
use crate::queries::molecule::v2::{
MoleculeAccessLevel,
MoleculeAccessLevelRuleInput,
MoleculeCategory,
MoleculeChangeBy,
MoleculeProjectV2,
Expand Down Expand Up @@ -172,6 +173,7 @@ pub struct MoleculeDataRoomEntriesFilters {
by_tags: Option<Vec<MoleculeTag>>,
by_categories: Option<Vec<MoleculeCategory>>,
by_access_levels: Option<Vec<MoleculeAccessLevel>>,
by_access_level_rules: Option<Vec<MoleculeAccessLevelRuleInput>>,
}

impl From<MoleculeDataRoomEntriesFilters> for kamu_molecule_domain::MoleculeDataRoomEntriesFilters {
Expand All @@ -180,6 +182,9 @@ impl From<MoleculeDataRoomEntriesFilters> for kamu_molecule_domain::MoleculeData
by_tags: value.by_tags,
by_categories: value.by_categories,
by_access_levels: value.by_access_levels,
by_access_level_rules: value
.by_access_level_rules
.map(|rules| rules.into_iter().map(Into::into).collect()),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use kamu_molecule_domain::{

use crate::prelude::*;
use crate::queries::molecule::v2::{
MoleculeAccessLevelRuleInput,
MoleculeActivityEventV2,
MoleculeActivityEventV2Connection,
MoleculeAnnouncementEntry,
Expand Down Expand Up @@ -213,6 +214,7 @@ pub struct MoleculeProjectActivityFilters {
pub by_tags: Option<Vec<String>>,
pub by_categories: Option<Vec<String>>,
pub by_access_levels: Option<Vec<String>>,
pub by_access_level_rules: Option<Vec<MoleculeAccessLevelRuleInput>>,
pub by_kinds: Option<Vec<MoleculeActivityKindInput>>,
}

Expand All @@ -222,6 +224,9 @@ impl From<MoleculeProjectActivityFilters> for kamu_molecule_domain::MoleculeActi
by_tags: value.by_tags,
by_categories: value.by_categories,
by_access_levels: value.by_access_levels,
by_access_level_rules: value
.by_access_level_rules
.map(|rules| rules.into_iter().map(Into::into).collect()),
by_kinds: value
.by_kinds
.map(|kinds| kinds.into_iter().map(Into::into).collect()),
Expand Down
5 changes: 5 additions & 0 deletions src/adapter/graphql/src/queries/molecule/v2/molecule_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use kamu_molecule_domain::{
use crate::molecule::molecule_subject;
use crate::prelude::*;
use crate::queries::molecule::v2::{
MoleculeAccessLevelRuleInput,
MoleculeActivityEventV2,
MoleculeActivityEventV2Connection,
MoleculeAnnouncementEntry,
Expand Down Expand Up @@ -342,6 +343,7 @@ pub struct MoleculeSemanticSearchFilters {
by_tags: Option<Vec<String>>,
by_categories: Option<Vec<String>>,
by_access_levels: Option<Vec<String>>,
by_access_level_rules: Option<Vec<MoleculeAccessLevelRuleInput>>,
by_kinds: Option<Vec<MoleculeSearchEntityKindInput>>,
}

Expand All @@ -352,6 +354,9 @@ impl From<MoleculeSemanticSearchFilters> for kamu_molecule_domain::MoleculeSearc
by_tags: value.by_tags,
by_categories: value.by_categories,
by_access_levels: value.by_access_levels,
by_access_level_rules: value
.by_access_level_rules
.map(|rules| rules.into_iter().map(Into::into).collect::<Vec<_>>()),
Comment thread
zaychenko-sergei marked this conversation as resolved.
by_kinds: value
.by_kinds
.map(|kinds| kinds.into_iter().map(Into::into).collect()),
Expand Down
147 changes: 147 additions & 0 deletions src/adapter/graphql/tests/tests/test_gql_custom_molecule_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9163,6 +9163,153 @@ async fn test_molecule_v2_activity() {
);
}

#[tokio::test]
async fn test_molecule_v2_activity_access_level_rules_filters() {
let harness = GraphQLMoleculeV1Harness::builder()
.tenancy_config(TenancyConfig::MultiTenant)
.build()
.await;

const PROJECT_1_UID: &str = "0xcaD88677CA87a7815728C72D74B4ff4982d54Fc9_201";
const PROJECT_2_UID: &str = "0xcaD88677CA87a7815728C72D74B4ff4982d54Fc9_202";

for (uid, addr, token_id) in [
(
PROJECT_1_UID,
"0xcaD88677CA87a7815728C72D74B4ff4982d54Fc9",
201,
),
(
PROJECT_2_UID,
"0xcaD88677CA87a7815728C72D74B4ff4982d54Fc9",
202,
),
] {
let token_id_str = token_id.to_string();
assert_eq!(
{
let res_json = GraphQLQueryRequest::new(
CREATE_PROJECT,
async_graphql::Variables::from_value(value!({
"ipnftSymbol": format!("sym{token_id}"),
"ipnftUid": uid,
"ipnftAddress": addr,
"ipnftTokenId": token_id_str,
})),
)
.execute(&harness.schema, &harness.catalog_authorized)
.await
.data
.into_json()
.unwrap();

res_json["molecule"]["v2"]["createProject"]["isSuccess"].as_bool()
},
Some(true),
);
}

async fn create_file(
harness: &GraphQLMoleculeV1Harness,
ipnft_uid: &str,
path: &str,
access_level: &str,
) -> String {
let mut res_json = GraphQLQueryRequest::new(
CREATE_VERSIONED_FILE,
async_graphql::Variables::from_value(value!({
"ipnftUid": ipnft_uid,
"path": path,
"content": base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(b"payload"),
"contentType": "text/plain",
"changeBy": USER_1,
"accessLevel": access_level,
"description": null,
"categories": null,
"tags": null,
"contentText": null,
"encryptionMetadata": null,
})),
)
.execute(&harness.schema, &harness.catalog_authorized)
.await
.data
.into_json()
.unwrap();

let mut upload_file_node =
res_json["molecule"]["v2"]["project"]["dataRoom"]["uploadFile"].take();

upload_file_node["entry"]["ref"]
.take()
.as_str()
.unwrap()
.to_owned()
}

let project_1_public = create_file(&harness, PROJECT_1_UID, "/p1-public.txt", "public").await;
let project_1_holders =
create_file(&harness, PROJECT_1_UID, "/p1-holders.txt", "holders").await;
let project_2_private =
create_file(&harness, PROJECT_2_UID, "/p2-private.txt", "private").await;

// Global activity filtered by scoped access rules should only include matching
// entries
assert_eq!(
GraphQLQueryRequest::new(
LIST_GLOBAL_ACTIVITY_QUERY,
async_graphql::Variables::from_json(json!({
"filters": {
"byAccessLevelRules": [
{ "ipnftUid": PROJECT_1_UID, "accessLevels": ["holders", "public"] },
{ "ipnftUid": PROJECT_2_UID, "accessLevels": ["private"] }
]
},
})),
)
.execute(&harness.schema, &harness.catalog_authorized)
.await
.data,
value!({
"molecule": {
"v2": {
"activity": {
"nodes": [
{
"__typename": "MoleculeActivityFileAddedV2",
"entry": {
"path": "/p2-private.txt",
"ref": project_2_private,
"accessLevel": "private",
"changeBy": USER_1,
}
},
{
"__typename": "MoleculeActivityFileAddedV2",
"entry": {
"path": "/p1-holders.txt",
"ref": project_1_holders,
"accessLevel": "holders",
"changeBy": USER_1,
}
},
{
"__typename": "MoleculeActivityFileAddedV2",
"entry": {
"path": "/p1-public.txt",
"ref": project_1_public,
"accessLevel": "public",
"changeBy": USER_1,
}
},
]
}
}
}
})
);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[test_log::test(tokio::test)]
Expand Down
2 changes: 2 additions & 0 deletions src/sku/molecule/domain/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

mod molecule_access_level_rule;
mod molecule_activity;
mod molecule_announcement;
mod molecule_data_room_activity;
Expand All @@ -15,6 +16,7 @@ mod molecule_encryption_metadata;
mod molecule_project;
mod molecule_versioned_file;

pub use molecule_access_level_rule::*;
pub use molecule_activity::*;
pub use molecule_announcement::*;
pub use molecule_data_room_activity::*;
Expand Down
18 changes: 18 additions & 0 deletions src/sku/molecule/domain/src/entities/molecule_access_level_rule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Kamu Data, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MoleculeAccessLevelRule {
pub ipnft_uid: Option<String>,
pub access_levels: Vec<String>,
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions src/sku/molecule/domain/src/entities/molecule_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use std::collections::HashSet;

use crate::MoleculeAccessLevelRule;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
Expand All @@ -30,6 +32,7 @@ pub struct MoleculeActivitiesFilters {
pub by_tags: Option<Vec<String>>,
pub by_categories: Option<Vec<String>>,
pub by_access_levels: Option<Vec<String>>,
pub by_access_level_rules: Option<Vec<MoleculeAccessLevelRule>>,
Comment thread
zaychenko-sergei marked this conversation as resolved.
pub by_kinds: Option<Vec<MoleculeActivityKind>>,
}

Expand Down
Loading
Loading