Skip to content

Commit

Permalink
Merge pull request #1531 from siddhantk232/refactor/remode-dead-code
Browse files Browse the repository at this point in the history
remove unused code
  • Loading branch information
siddhantk232 authored Nov 27, 2023
2 parents 5e13cd7 + 08d419d commit e01310c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 100 deletions.
3 changes: 3 additions & 0 deletions fastn-core/src/library/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub fn convert_to_document_id(doc_name: &str) -> String {
format!("/{}/", document_id)
}

#[allow(dead_code)]
/// We might use this in future
/// would be helpful if this is documented properly
pub fn document_full_id(
req_config: &fastn_core::RequestConfig,
doc: &ftd::ftd2021::p2::TDoc,
Expand Down
100 changes: 0 additions & 100 deletions fastn-core/src/package/user_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,103 +563,3 @@ pub async fn access_identities(
e => e,
}
}

pub mod processor {
use itertools::Itertools;

pub fn user_groups(
section: &ftd::ftd2021::p1::Section,
doc: &ftd::ftd2021::p2::TDoc,
config: &fastn_core::Config,
) -> ftd::ftd2021::p1::Result<ftd::Value> {
let g = config
.package
.groups
.values()
.map(|g| g.to_group_compat())
.collect_vec();
doc.from_json(&g, section)
}

pub fn user_group_by_id(
section: &ftd::ftd2021::p1::Section,
doc: &ftd::ftd2021::p2::TDoc,
config: &fastn_core::Config,
) -> ftd::ftd2021::p1::Result<ftd::Value> {
let id = section.header.str(doc.name, section.line_number, "id")?;
let g = config
.package
.groups
.get(id)
.map(|g| g.to_group_compat())
.ok_or_else(|| ftd::ftd2021::p1::Error::NotFound {
key: format!("user-group: `{}` not found", id),
doc_id: doc.name.to_string(),
line_number: section.line_number,
})?;
doc.from_json(&g, section)
}

pub fn get_identities(
section: &ftd::ftd2021::p1::Section,
doc: &ftd::ftd2021::p2::TDoc,
req_config: &fastn_core::RequestConfig,
) -> ftd::ftd2021::p1::Result<ftd::Value> {
let doc_id = fastn_core::library::document::document_full_id(req_config, doc)?;
let identities =
super::get_identities(&req_config.config, doc_id.as_str(), true).map_err(|e| {
ftd::ftd2021::p1::Error::ParseError {
message: e.to_string(),
doc_id,
line_number: section.line_number,
}
})?;

Ok(ftd::Value::List {
data: identities
.into_iter()
.map(|i| ftd::PropertyValue::Value {
value: ftd::Value::String {
text: i.to_string(),
source: ftd::TextSource::Default,
},
})
.collect_vec(),
kind: ftd::ftd2021::p2::Kind::List {
kind: Box::new(ftd::ftd2021::p2::Kind::String {
caption: false,
body: false,
default: None,
is_reference: false,
}),
default: None,
is_reference: false,
},
})
}

// is user can_read the document or not based on defined readers in sitemap
pub async fn is_reader<'a>(
section: &ftd::ftd2021::p1::Section,
doc: &'a ftd::ftd2021::p2::TDoc<'_>,
req_config: &fastn_core::RequestConfig,
) -> ftd::ftd2021::p1::Result<ftd::Value> {
let doc_id = fastn_core::library::document::document_full_id(req_config, doc)?;
let is_reader = req_config.can_read(&doc_id, false).await.map_err(|e| {
ftd::ftd2021::p1::Error::ParseError {
message: e.to_string(),
doc_id,
line_number: section.line_number,
}
})?;

Ok(ftd::Value::Boolean { value: is_reader })
}
}

#[cfg(test)]
mod tests {
// TODO:
#[test]
fn get_identities() {}
}

0 comments on commit e01310c

Please sign in to comment.