Skip to content

Commit

Permalink
fix: order labels, update status checks, fix notifications (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist authored Jun 20, 2024
1 parent 83d9987 commit 59cd41b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::access_control::members::ActionType;
use crate::access_control::members::Member;
use crate::access_control::AccessControl;
use community::*;
use near_sdk::json_types::Base64VecU8;
use post::*;
use proposal::timeline::TimelineStatus;
use proposal::*;
Expand Down Expand Up @@ -733,14 +734,16 @@ impl Contract {
}

pub fn get_global_labels(&self) -> Vec<LabelInfoExtended> {
self.global_labels_info
let mut result: Vec<LabelInfoExtended> = self.global_labels_info
.iter()
.map(|(label, label_info)| LabelInfoExtended {
value: label.clone(),
title: label_info.title.clone(),
color: label_info.color.clone(),
})
.collect()
.collect();
result.sort_by(|a, b| a.value.cmp(&b.value));
result
}

pub fn get_rfp_linked_proposals(&self, rfp_id: RFPId) -> Vec<ProposalId> {
Expand Down Expand Up @@ -1184,7 +1187,7 @@ mod tests {
&receipts[2].actions[0]
{
assert_eq!(method_name, b"set");
assert_eq!(args, b"{\"data\":{\"bob.near\":{\"index\":{\"notify\":\"[{\\\"key\\\":\\\"petersalomonsen.near\\\",\\\"value\\\":{\\\"type\\\":\\\"devhub/mention\\\",\\\"proposal\\\":0,\\\"notifier\\\":\\\"bob.near\\\"}},{\\\"key\\\":\\\"psalomo.near.\\\",\\\"value\\\":{\\\"type\\\":\\\"devhub/mention\\\",\\\"proposal\\\":0,\\\"notifier\\\":\\\"bob.near\\\"}},{\\\"key\\\":\\\"frol.near\\\",\\\"value\\\":{\\\"type\\\":\\\"devhub/mention\\\",\\\"proposal\\\":0,\\\"notifier\\\":\\\"bob.near\\\"}},{\\\"key\\\":\\\"neardevdao.near\\\",\\\"value\\\":{\\\"type\\\":\\\"devhub/mention\\\",\\\"proposal\\\":0,\\\"notifier\\\":\\\"bob.near\\\"}}]\"}}}}");
assert_eq!(args, b"{\"data\":{\"bob.near\":{\"index\":{\"notify\":\"[{\\\"key\\\":\\\"petersalomonsen.near\\\",\\\"value\\\":{\\\"type\\\":\\\"proposal/mention\\\",\\\"proposal\\\":0,\\\"widgetAccountId\\\":\\\"bob.near\\\",\\\"notifier\\\":\\\"bob.near\\\"}},{\\\"key\\\":\\\"psalomo.near.\\\",\\\"value\\\":{\\\"type\\\":\\\"proposal/mention\\\",\\\"proposal\\\":0,\\\"widgetAccountId\\\":\\\"bob.near\\\",\\\"notifier\\\":\\\"bob.near\\\"}},{\\\"key\\\":\\\"frol.near\\\",\\\"value\\\":{\\\"type\\\":\\\"proposal/mention\\\",\\\"proposal\\\":0,\\\"widgetAccountId\\\":\\\"bob.near\\\",\\\"notifier\\\":\\\"bob.near\\\"}},{\\\"key\\\":\\\"neardevdao.near\\\",\\\"value\\\":{\\\"type\\\":\\\"proposal/mention\\\",\\\"proposal\\\":0,\\\"widgetAccountId\\\":\\\"bob.near\\\",\\\"notifier\\\":\\\"bob.near\\\"}}]\"}}}}");
} else {
assert!(false, "Expected a function call ...")
}
Expand Down
9 changes: 6 additions & 3 deletions src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ pub fn notify_proposal_subscribers(proposal: &Proposal) -> Promise {
env::current_account_id(),
accounts,
json!({
"type": "devhub/mention",
"type": "proposal/mention",
"proposal": proposal.id,
"widgetAccountId": env::current_account_id(),
"notifier": env::predecessor_account_id(),
}),
)
Expand All @@ -93,8 +94,9 @@ pub fn notify_rfp_subscribers(rfp: &RFP, additional_accounts: HashSet<AccountId>
env::current_account_id(),
accounts,
json!({
"type": "devhub/mention",
"type": "rfp/mention",
"rfp": rfp.id,
"widgetAccountId": env::current_account_id(),
"notifier": env::current_account_id(),
}),
)
Expand Down Expand Up @@ -130,8 +132,9 @@ pub fn notify_edit_proposal(proposal_id: ProposalId, post_author: AccountId) ->
env::current_account_id(),
post_author,
json!({
"type": "devhub/edit",
"type": "proposal/edit",
"proposal": proposal_id,
"widgetAccountId": env::current_account_id(),
"notifier": env::predecessor_account_id(),
}),
)
Expand Down
11 changes: 9 additions & 2 deletions src/proposal/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ impl TimelineStatus {
}
}

pub fn is_approved(&self) -> bool {
matches!(self, TimelineStatus::Approved(..))
pub fn was_approved(&self) -> bool {
match self {
TimelineStatus::Approved(..) => true,
TimelineStatus::ApprovedConditionally(..) => true,
TimelineStatus::PaymentProcessing(..) => true,
TimelineStatus::Funded(..) => true,
_ => false,

}
}

pub fn get_review_status(&self) -> &ReviewStatus {
Expand Down
2 changes: 1 addition & 1 deletion src/rfp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Contract {
let has_approved_proposal = self.get_rfp_linked_proposals(id)
.into_iter()
.filter_map(|proposal_id| self.proposals.get(proposal_id.into()))
.any(|proposal| Into::<Proposal>::into(proposal).snapshot.body.latest_version().timeline.is_approved());
.any(|proposal| Into::<Proposal>::into(proposal).snapshot.body.latest_version().timeline.was_approved());
require!(has_approved_proposal, "Cannot change RFP status to Proposal Selected without an approved proposal linked to this RFP");
}

Expand Down

0 comments on commit 59cd41b

Please sign in to comment.