Skip to content

Commit

Permalink
misc: UserBlockingRule renamed to AccountBlockingRule
Browse files Browse the repository at this point in the history
  • Loading branch information
donosonaumczuk committed Dec 29, 2024
1 parent 916dc6b commit 07947f7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
20 changes: 10 additions & 10 deletions contracts/dashboard/factories/LensFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract LensFactory {
GraphFactory internal immutable GRAPH_FACTORY;
UsernameFactory internal immutable USERNAME_FACTORY;
IAccessControl internal immutable _factoryOwnedAccessControl;
address internal immutable _userBlockingRule;
address internal immutable _accountBlockingRule;
address internal immutable _groupGatedFeedRule;

constructor(
Expand All @@ -66,7 +66,7 @@ contract LensFactory {
FeedFactory feedFactory,
GraphFactory graphFactory,
UsernameFactory usernameFactory,
address userBlockingRule,
address accountBlockingRule,
address groupGatedFeedRule
) {
ACCESS_CONTROL_FACTORY = accessControlFactory;
Expand All @@ -77,7 +77,7 @@ contract LensFactory {
GRAPH_FACTORY = graphFactory;
USERNAME_FACTORY = usernameFactory;
_factoryOwnedAccessControl = new RoleBasedAccessControl({owner: address(this)});
_userBlockingRule = userBlockingRule;
_accountBlockingRule = accountBlockingRule;
_groupGatedFeedRule = groupGatedFeedRule;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ contract LensFactory {
RuleSelectorChange({ruleSelector: IFeedRule.processCreatePost.selector, isRequired: true, enabled: true});

modifiedFeedRules[0] = RuleChange({
ruleAddress: _userBlockingRule,
ruleAddress: _accountBlockingRule,
configSalt: bytes32(0),
configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}),
selectorChanges: selectorChanges
Expand All @@ -166,7 +166,7 @@ contract LensFactory {
});

for (uint256 i = 0; i < feedRules.length; i++) {
require(feedRules[i].ruleAddress != _userBlockingRule, "UserBlockingRule was already prepended");
require(feedRules[i].ruleAddress != _accountBlockingRule, "AccountBlockingRule was already prepended");
require(feedRules[i].ruleAddress != _groupGatedFeedRule, "GroupGatedRule was already prepended");
modifiedFeedRules[i + 2] = feedRules[i];
}
Expand Down Expand Up @@ -228,12 +228,12 @@ contract LensFactory {
return FEED_FACTORY.deployFeed(
metadataURI,
_deployAccessControl(owner, admins),
_prependUserBlocking(rules, IFeedRule.processCreatePost.selector),
_prependAccountBlocking(rules, IFeedRule.processCreatePost.selector),
extraData
);
}

function _prependUserBlocking(
function _prependAccountBlocking(
RuleChange[] calldata rules,
bytes4 ruleSelector
) internal view returns (RuleChange[] memory) {
Expand All @@ -243,13 +243,13 @@ contract LensFactory {
selectorChanges[0] = RuleSelectorChange({ruleSelector: ruleSelector, isRequired: true, enabled: true});

modifiedRules[0] = RuleChange({
ruleAddress: _userBlockingRule,
ruleAddress: _accountBlockingRule,
configSalt: bytes32(0),
configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}),
selectorChanges: selectorChanges
});
for (uint256 i = 0; i < rules.length; i++) {
require(rules[i].ruleAddress != _userBlockingRule, "UserBlockingRule was already prepended");
require(rules[i].ruleAddress != _accountBlockingRule, "AccountBlockingRule was already prepended");
modifiedRules[i + 1] = rules[i];
}

Expand All @@ -266,7 +266,7 @@ contract LensFactory {
return GRAPH_FACTORY.deployGraph(
metadataURI,
_deployAccessControl(owner, admins),
_prependUserBlocking(rules, IGraphRule.processFollow.selector),
_prependAccountBlocking(rules, IGraphRule.processFollow.selector),
extraData
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ import {KeyValue, RuleChange} from "./../../core/types/Types.sol";
import {IFeed} from "./../../core/interfaces/IFeed.sol";
import {MetadataBased} from "./../../core/base/MetadataBased.sol";

contract UserBlockingRule is IFeedRule, IGraphRule, MetadataBased {
event Lens_UserBlocking_UserBlocked(address indexed source, address indexed target, uint256 timestamp);
event Lens_UserBlocking_UserUnblocked(address indexed source, address indexed target);
contract AccountBlockingRule is IFeedRule, IGraphRule, MetadataBased {
event Lens_AccountBlocking_AccountBlocked(address indexed source, address indexed target, uint256 timestamp);
event Lens_AccountBlocking_UserUnblocked(address indexed source, address indexed target);

event Lens_Rule_MetadataURISet(string metadataURI);

mapping(address => mapping(address => uint256)) public userBlocks;
mapping(address => mapping(address => uint256)) public accountBlocks;

constructor(string memory metadataURI) {
constructor(
string memory metadataURI
) {
_setMetadataURI(metadataURI);
}

function _emitMetadataURISet(string memory metadataURI) internal override {
function _emitMetadataURISet(
string memory metadataURI
) internal override {
emit Lens_Rule_MetadataURISet(metadataURI);
}

Expand All @@ -33,12 +37,12 @@ contract UserBlockingRule is IFeedRule, IGraphRule, MetadataBased {
function blockUser(address source, address target) external {
require(msg.sender == source, "Only the source can block a user");
require(source != target, "Cannot block self");
userBlocks[source][target] = block.timestamp;
accountBlocks[source][target] = block.timestamp;
}

function unblockUser(address source, address target) external {
require(msg.sender == source, "Only the source can unblock a user");
userBlocks[msg.sender][target] = 0;
accountBlocks[msg.sender][target] = 0;
}

function processCreatePost(
Expand Down Expand Up @@ -80,7 +84,7 @@ contract UserBlockingRule is IFeedRule, IGraphRule, MetadataBased {
}

function _isBlocked(address source, address blockTarget) internal view returns (bool) {
return userBlocks[source][blockTarget] > 0;
return accountBlocks[source][blockTarget] > 0;
}

// Unimplemented functions
Expand Down
4 changes: 2 additions & 2 deletions deploy/deployFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function deployFactories(): Promise<void> {
{ contractName: 'GroupFactory', contractType: ContractType.Factory },
{ contractName: 'UsernameFactory', contractType: ContractType.Factory },
{
contractName: 'UserBlockingRule',
contractName: 'AccountBlockingRule',
contractType: ContractType.Rule,
constructorArguments: [metadataURI],
},
Expand All @@ -37,7 +37,7 @@ export default async function deployFactories(): Promise<void> {
deployedContracts['FeedFactory'].address,
deployedContracts['GraphFactory'].address,
deployedContracts['UsernameFactory'].address,
deployedContracts['UserBlockingRule'].address,
deployedContracts['AccountBlockingRule'].address,
deployedContracts['GroupGatedFeedRule'].address,
];

Expand Down
6 changes: 3 additions & 3 deletions test/factories/LensFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {Username} from "../../contracts/core/primitives/username/Username.sol";
import {RuleChange, DataElement, SourceStamp, RuleExecutionData} from "../../contracts/core/types/Types.sol";
import {AccountManagerPermissions} from "../../contracts/dashboard/account/Account.sol";
import {AccessControlFactory} from "../../contracts/dashboard/factories/AccessControlFactory.sol";
import {UserBlockingRule} from "../../contracts/rules/base/UserBlockingRule.sol";
import {AccountBlockingRule} from "../../contracts/rules/base/AccountBlockingRule.sol";
import {IGraph} from "../../contracts/core/interfaces/IGraph.sol";
import "../helpers/TypeHelpers.sol";

Expand All @@ -23,7 +23,7 @@ contract LensFactoryTest is Test {
Username username;

function setUp() public {
UserBlockingRule userBlockingRule = new UserBlockingRule();
AccountBlockingRule accountBlockingRule = new AccountBlockingRule();

lensFactory = new LensFactory({
accessControlFactory: new AccessControlFactory(),
Expand All @@ -33,7 +33,7 @@ contract LensFactoryTest is Test {
feedFactory: new FeedFactory(),
graphFactory: new GraphFactory(),
usernameFactory: new UsernameFactory(),
userBlockingRule: address(userBlockingRule)
accountBlockingRule: address(accountBlockingRule)
});

username = Username(
Expand Down

0 comments on commit 07947f7

Please sign in to comment.