Skip to content

Commit

Permalink
Allowing editors to leave spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed May 24, 2024
1 parent 1e8b003 commit df84104
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/contracts/src/base/IEditors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ interface IEditors {
/// @param editor The address of the editor being removed.
event EditorRemoved(address dao, address editor);

/// @notice Emitted when an editor left the space.
/// @param dao The address of the DAO whose plugin has lost an editor.
/// @param editor The address of the editor leaving.
event EditorLeft(address dao, address editor);

/// @notice Checks if an account is an editor on the DAO.
/// @param _account The address of the account to be checked.
/// @return Whether the account is an editor or not.
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/src/governance/MainVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
/// @notice Raised when attempting to remove the last editor
error NoEditorsLeft();

/// @notice Raised when a non-editor attempts to leave a space
error NotAnEditor();

/// @notice Raised when a wallet who is not an editor or a member attempts to do something
error NotAMember(address caller);

Expand Down Expand Up @@ -144,6 +147,19 @@ contract MainVotingPlugin is Addresslist, MajorityVotingBase, IEditors, IMembers
emit MemberRemoved(address(dao()), _account);
}

/// @notice Removes
function leaveSpace() public {
if (!isEditor(msg.sender)) {
revert NotAnEditor();
} else if (addresslistLength() <= 1) revert NoEditorsLeft();

address[] memory _editors = new address[](1);
_editors[0] = msg.sender;

_removeAddresses(_editors);
emit EditorLeft(address(dao()), msg.sender);
}

/// @notice Returns whether the given address is currently listed as an editor
function isEditor(address _account) public view returns (bool) {
return isListed(_account);
Expand Down
42 changes: 28 additions & 14 deletions packages/contracts/src/personal/PersonalSpaceAdminPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,34 @@ contract PersonalSpaceAdminPlugin is PluginCloneable, ProposalUpgradeable, IEdit
emit MemberRemoved(address(dao()), _member);
}

/// @notice Creates and executes a proposal that makes the DAO revoke membership permission from the sender address
function leaveSpace() public auth(MEMBER_PERMISSION_ID) {
IDAO.Action[] memory _actions = new IDAO.Action[](1);
_actions[0].to = address(dao());
_actions[0].data = abi.encodeCall(
PermissionManager.revoke,
(address(this), msg.sender, MEMBER_PERMISSION_ID)
);

uint256 _proposalId = _createProposal(msg.sender, _actions);

dao().execute(bytes32(_proposalId), _actions, 0);

emit MemberLeft(address(dao()), msg.sender);
/// @notice Creates and executes a proposal that makes the DAO revoke any permission from the sender address
function leaveSpace() public {
IDAO.Action[] memory _actions;
if (dao().hasPermission(address(this), msg.sender, MEMBER_PERMISSION_ID, bytes(""))) {
_actions = new IDAO.Action[](1);
_actions[0].to = address(dao());
_actions[0].data = abi.encodeCall(
PermissionManager.revoke,
(address(this), msg.sender, MEMBER_PERMISSION_ID)
);

uint256 _proposalId = _createProposal(msg.sender, _actions);
dao().execute(bytes32(_proposalId), _actions, 0);
emit MemberLeft(address(dao()), msg.sender);
}

if (isEditor(msg.sender)) {
_actions = new IDAO.Action[](1);
_actions[0].to = address(dao());
_actions[0].data = abi.encodeCall(
PermissionManager.revoke,
(address(this), msg.sender, EDITOR_PERMISSION_ID)
);

uint256 _proposalId = _createProposal(msg.sender, _actions);
dao().execute(bytes32(_proposalId), _actions, 0);
emit EditorLeft(address(dao()), msg.sender);
}
}

/// @notice Creates and executes a proposal that makes the DAO grant editor permission to the given address
Expand Down

0 comments on commit df84104

Please sign in to comment.