Skip to content

Commit

Permalink
feat: community censorship status
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Oct 16, 2024
1 parent 9e38bba commit a9cb76e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/base/constants/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub struct CommunityDetails {
pub community_metadata_uri: ByteArray,
pub community_nft_address: ContractAddress,
pub community_total_members: u256,
pub community_censorship: bool,
pub community_premium_status: bool,
pub community_type: CommunityType
}
Expand Down
29 changes: 29 additions & 0 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,25 @@ pub mod CommunityComponent {
);
}

/// @notice set the censorship status of a community
/// @param community_id The id of the community
fn set_community_censorship_status(
ref self: ComponentState<TContractState>, community_id: u256, censorship_status: bool
) {
let mut community = self.communities.read(community_id);

// check caller is owner
assert(community.community_owner == get_caller_address(), UNAUTHORIZED);

// update storage
community.community_censorship = censorship_status;
self.communities.write(community_id, community);
}

// *************************************************************************
// GETTERS
// *************************************************************************

/// @notice gets a particular community details
/// @param community_id id of community to be returned
/// @return CommunityDetails details of the community
Expand Down Expand Up @@ -423,6 +442,15 @@ pub mod CommunityComponent {
}
}

/// @notice checks if a community is censored
/// @param community_id the id of the community
/// @return bool the censorship status
fn get_community_censorship_status(
self: @ComponentState<TContractState>, community_id: u256
) -> bool {
self.communities.read(community_id).community_censorship
}

/// @notice gets ban status for a particular user
/// @param profile profile to check ban status
/// @param community_id id of community to be returned
Expand Down Expand Up @@ -504,6 +532,7 @@ pub mod CommunityComponent {
community_nft_address: community_nft_address,
community_premium_status: false,
community_total_members: 0,
community_censorship: false,
community_type: CommunityType::Free,
};

Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub trait ICommunity<TState> {
fn set_community_fee_address(
ref self: TState, community_id: u256, _fee_address: ContractAddress
);
fn set_community_censorship_status(
ref self: TState, community_id: u256, censorship_status: bool
);
fn upgrade_community(
ref self: TState,
community_id: u256,
Expand Down Expand Up @@ -56,6 +59,7 @@ pub trait ICommunity<TState> {
) -> (bool, CommunityMember);
fn get_total_members(self: @TState, community_id: u256) -> u256;
fn is_community_mod(self: @TState, profile: ContractAddress, community_id: u256) -> bool;
fn get_community_censorship_status(self: @TState, community_id: u256) -> bool;
fn get_ban_status(self: @TState, profile: ContractAddress, community_id: u256) -> bool;
fn get_community_fee_address(self: @TState, community_id: u256) -> ContractAddress;
fn is_premium_community(self: @TState, community_id: u256) -> (bool, CommunityType);
Expand Down
34 changes: 33 additions & 1 deletion tests/test_community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,41 @@ fn test_should_panic_if_caller_removing_mod_is_not_owner() {
}

#[test]
fn test_set_ban_status_by_owner() {
fn test_set_censorship_status() {
let (community_contract_address, _) = __setup__();
let communityDispatcher = ICommunityDispatcher { contract_address: community_contract_address };

//create the community
start_cheat_caller_address(community_contract_address, USER_ONE.try_into().unwrap());
let community_id = communityDispatcher.create_community();

// set censorship status
communityDispatcher.set_community_censorship_status(community_id, true);

// check censorship status was set to true
let censorship_status = communityDispatcher.get_community_censorship_status(community_id);
assert(censorship_status == true, 'invalid censorship status');
stop_cheat_caller_address(community_contract_address);
}

#[test]
#[should_panic(expected: ('Karst: user unauthorized!',))]
fn test_only_owner_can_set_censorship_status() {
let (community_contract_address, _) = __setup__();
let communityDispatcher = ICommunityDispatcher { contract_address: community_contract_address };

//create the community
start_cheat_caller_address(community_contract_address, USER_ONE.try_into().unwrap());
let community_id = communityDispatcher.create_community();
stop_cheat_caller_address(community_contract_address);

// set censorship status
communityDispatcher.set_community_censorship_status(community_id, true);
}

#[test]
fn test_set_ban_status_by_owner() {
let (community_contract_address, _) = __setup__();
let communityDispatcher = ICommunityDispatcher { contract_address: community_contract_address };

//create the community
Expand Down

0 comments on commit a9cb76e

Please sign in to comment.