Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added blog url and campaign / social short link tracking #145

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
rununittest:
name: Unit tests
Expand Down
42 changes: 19 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Release
on:
push:
branches: [ main ]
branches: [main]
workflow_dispatch:
inputs:
environment:
description: 'Account to deploy'
description: "Account to deploy"
type: environment
required: true

Expand All @@ -21,24 +21,20 @@ jobs:
environment: ${{ inputs.environment || 'devhub.near' }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v1
- name: Install cargo-near
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
- name: Build community factory contract
run: cd community-factory && cargo near build
- name: Build devhub contract
run: cargo near build
- name: Install near CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.3.1/near-cli-rs-v0.3.1-installer.sh | sh
- name: Deploy contract
run: |
output=$(near contract call-function as-transaction "$NEAR_DEVHUB_ACCOUNT_ID" unsafe_self_upgrade file-args ./target/near/devhub.wasm prepaid-gas '200 TeraGas' attached-deposit '0 NEAR' sign-as "$NEAR_DEVHUB_ACCOUNT_ID" network-config "$NEAR_NETWORK_CONNECTION" sign-with-plaintext-private-key --signer-public-key "$NEAR_DEVHUB_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_DEVHUB_ACCOUNT_PRIVATE_KEY" send)
while [[ ! "$output" == *"Migration done."* ]]; do
echo "$output"
sleep 5
output=$(near contract call-function as-transaction "$NEAR_DEVHUB_ACCOUNT_ID" unsafe_migrate json-args '{}' prepaid-gas '100 TeraGas' attached-deposit '0 NEAR' sign-as "$NEAR_DEVHUB_ACCOUNT_ID" network-config "$NEAR_NETWORK_CONNECTION" sign-with-plaintext-private-key --signer-public-key "$NEAR_DEVHUB_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_DEVHUB_ACCOUNT_PRIVATE_KEY" send)
done
echo "$output"
- name: Checkout repository
uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v1
- name: Install cargo-near
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
- name: Build community factory contract
run: cd community-factory && cargo near build
- name: Build devhub contract
run: cargo near build
- name: Install near CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.3.1/near-cli-rs-v0.3.1-installer.sh | sh
- name: Deploy contract
run: |
output=$(near contract call-function as-transaction "$NEAR_DEVHUB_ACCOUNT_ID" unsafe_self_upgrade file-args ./target/near/devhub.wasm prepaid-gas '200 TeraGas' attached-deposit '0 NEAR' sign-as "$NEAR_DEVHUB_ACCOUNT_ID" network-config "$NEAR_NETWORK_CONNECTION" sign-with-plaintext-private-key --signer-public-key "$NEAR_DEVHUB_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_DEVHUB_ACCOUNT_PRIVATE_KEY" send)
while [[ ! "$output" == *"Migration done."* ]]; do
echo "$output"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
neardev/
target/
res/*.wasm
.DS_Store
.DS_Store
.vscode
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ near-contract-standards.workspace = true
serde_json = { version = "1.0", features = ["preserve_order"] }
devhub_common.workspace = true
html-escape = "0.2.13"
urlencoding = "2.1.3"

[dev-dependencies]
near-sdk = { workspace = true, features = ["unit-testing"] }
Expand Down
60 changes: 39 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod access_control;
pub mod common;
pub mod community;
pub mod debug;
pub mod migrations;
mod notify;
pub mod common;
pub mod proposal;
pub mod rfp;
pub mod stats;
Expand All @@ -16,7 +16,7 @@ use crate::access_control::AccessControl;
use community::*;

use common::*;
use proposal::timeline::{TimelineStatusV1, TimelineStatus, VersionedTimelineStatus};
use proposal::timeline::{TimelineStatus, TimelineStatusV1, VersionedTimelineStatus};
use proposal::*;
use rfp::{
RFPId, RFPSnapshot, TimelineStatus as RFPTimelineStatus, VersionedRFP, VersionedRFPBody, RFP,
Expand All @@ -26,13 +26,13 @@ use devhub_common::{social_db_contract, SetReturnType};

use near_sdk::borsh::BorshDeserialize;
use near_sdk::collections::{LookupMap, UnorderedMap, Vector};
use near_sdk::store::Lazy;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::serde_json::{json, Number, Value};
use near_sdk::store::Lazy;
use near_sdk::{env, near, require, AccountId, NearSchema, PanicOnDefault, Promise};
use web4::types::{Web4Request, Web4Response};

use std::collections::{HashSet, HashMap};
use std::collections::{HashMap, HashSet};
use std::convert::TryInto;

type PostId = u64;
Expand Down Expand Up @@ -90,12 +90,9 @@ impl Contract {
contract
}

pub fn get_proposals(&self, ids: Option< Vec<ProposalId> >) -> Vec<VersionedProposal> {
pub fn get_proposals(&self, ids: Option<Vec<ProposalId>>) -> Vec<VersionedProposal> {
if let Some(ids) = ids {
ids
.into_iter()
.filter_map(|id| self.proposals.get(id.into()))
.collect()
ids.into_iter().filter_map(|id| self.proposals.get(id.into())).collect()
} else {
self.proposals.to_vec()
}
Expand Down Expand Up @@ -140,7 +137,10 @@ impl Contract {
"Terms and conditions version cannot be from the future"
);
} else {
require!(env::current_account_id() != "devhub.near", "Accepted terms and conditions version is required");
require!(
env::current_account_id() != "devhub.near",
"Accepted terms and conditions version is required"
);
}

let proposal_body = body.clone().latest_version();
Expand Down Expand Up @@ -301,7 +301,7 @@ impl Contract {
res.sort();
res
}

pub fn get_all_authors(&self) -> Vec<AccountId> {
let mut res: Vec<_> = self.authors.keys().collect();
res.sort();
Expand Down Expand Up @@ -453,7 +453,11 @@ impl Contract {
}

#[payable]
pub fn edit_proposal_timeline(&mut self, id: ProposalId, timeline: TimelineStatusV1) -> ProposalId {
pub fn edit_proposal_timeline(
&mut self,
id: ProposalId,
timeline: TimelineStatusV1,
) -> ProposalId {
let proposal: Proposal = self
.proposals
.get(id.into())
Expand Down Expand Up @@ -484,7 +488,11 @@ impl Contract {
}

#[payable]
pub fn edit_proposal_linked_rfp(&mut self, id: ProposalId, rfp_id: Option<RFPId>) -> ProposalId {
pub fn edit_proposal_linked_rfp(
&mut self,
id: ProposalId,
rfp_id: Option<RFPId>,
) -> ProposalId {
let proposal: Proposal = self
.proposals
.get(id.into())
Expand All @@ -507,12 +515,20 @@ impl Contract {
}

#[payable]
pub fn cancel_rfp(&mut self, id: RFPId, proposals_to_cancel: Vec<ProposalId>, proposals_to_unlink: Vec<ProposalId>) -> RFPId {
pub fn cancel_rfp(
&mut self,
id: RFPId,
proposals_to_cancel: Vec<ProposalId>,
proposals_to_unlink: Vec<ProposalId>,
) -> RFPId {
for proposal_id in proposals_to_cancel {
let proposal: Proposal = self.get_proposal(proposal_id).into();
let proposal_timeline = proposal.snapshot.body.latest_version().timeline;
let review_status = proposal_timeline.latest_version().get_review_status().clone();
self.edit_proposal_versioned_timeline(proposal_id, TimelineStatus::Cancelled(review_status).into());
self.edit_proposal_versioned_timeline(
proposal_id,
TimelineStatus::Cancelled(review_status).into(),
);
}

for proposal_id in proposals_to_unlink {
Expand All @@ -536,7 +552,8 @@ impl Contract {
}

pub fn get_global_labels(&self) -> Vec<LabelInfoExtended> {
let mut result: Vec<LabelInfoExtended> = self.global_labels_info
let mut result: Vec<LabelInfoExtended> = self
.global_labels_info
.iter()
.map(|(label, label_info)| LabelInfoExtended {
value: label.clone(),
Expand All @@ -549,9 +566,7 @@ impl Contract {
}

pub fn get_rfp_linked_proposals(&self, rfp_id: RFPId) -> Vec<ProposalId> {
self.get_linked_proposals_in_rfp(rfp_id)
.into_iter()
.collect()
self.get_linked_proposals_in_rfp(rfp_id).into_iter().collect()
}

#[payable]
Expand Down Expand Up @@ -884,10 +899,13 @@ impl Contract {
pub fn web4_get(&self, request: Web4Request) -> Web4Response {
web4::handler::web4_get(self, request)
}

pub fn set_social_db_profile_description(&self, description: String) -> Promise {
let editor = env::predecessor_account_id();
require!(editor == env::current_account_id() || self.has_moderator(editor), "Permission denied");
require!(
editor == env::current_account_id() || self.has_moderator(editor),
"Permission denied"
);
social_db_contract()
.with_static_gas(env::prepaid_gas().saturating_div(3))
.with_attached_deposit(env::attached_deposit())
Expand Down
Loading