fix: Added owner validation that was missed after refactor + skip changing config on mint

This commit is contained in:
donosonaumczuk
2023-02-10 17:56:31 +00:00
parent 416f606de5
commit 7432ed3ce7
2 changed files with 15 additions and 21 deletions

View File

@@ -765,7 +765,10 @@ contract LensHub is LensNFTBase, VersionedInitializable, LensMultiState, LensHub
address to,
uint256 tokenId
) internal override whenNotPaused {
GeneralLib.switchToNewFreshDelegatedExecutorsConfig(tokenId);
// Switches to new fresh delegated executors configuration (except on minting, as it already has a fresh setup).
if (from != address(0)) {
GeneralLib.switchToNewFreshDelegatedExecutorsConfig(tokenId);
}
super._beforeTokenTransfer(from, to, tokenId);
}

View File

@@ -120,6 +120,7 @@ library GeneralLib {
address[] calldata executors,
bool[] calldata approvals
) external {
GeneralHelpers.validateAddressIsProfileOwner(msg.sender, delegatorProfileId);
DataTypes.DelegatedExecutorsConfig storage _delegatedExecutorsConfig = GeneralHelpers
.getDelegatedExecutorsConfig(delegatorProfileId);
_changeDelegatedExecutorsConfig(
@@ -139,6 +140,7 @@ library GeneralLib {
uint64 configNumber,
bool switchToGivenConfig
) external {
GeneralHelpers.validateAddressIsProfileOwner(msg.sender, delegatorProfileId);
_changeDelegatedExecutorsConfig(
GeneralHelpers.getDelegatedExecutorsConfig(delegatorProfileId),
delegatorProfileId,
@@ -478,43 +480,32 @@ library GeneralLib {
if (executors.length != approvals.length) {
revert Errors.ArrayMismatch();
}
(
uint64 configNumberToUse,
bool configSwitched
) = _prepareStorageToApplyChangesUnderGivenConfig(
_delegatedExecutorsConfig,
configNumber,
switchToGivenConfig
);
bool configSwitched = _prepareStorageToApplyChangesUnderGivenConfig(
_delegatedExecutorsConfig,
configNumber,
switchToGivenConfig
);
uint256 i;
while (i < executors.length) {
_delegatedExecutorsConfig.isApproved[configNumberToUse][executors[i]] = approvals[i];
_delegatedExecutorsConfig.isApproved[configNumber][executors[i]] = approvals[i];
unchecked {
++i;
}
}
emit Events.DelegatedExecutorsConfigChanged(
delegatorProfileId,
configNumberToUse,
configNumber,
executors,
approvals,
configSwitched
);
}
/**
* @param _delegatedExecutorsConfig The delegated executor configuration to prepare for changes.
* @param configNumber The number of the configuration where the executor approval state is being set.
* @param switchToGivenConfig A boolean indicanting if the configuration will be switched to the one with the given
* number.
*
* @return (uint64, bool) A tuple that represents (uint64 configNumberToUse, bool configSwitched).
*/
function _prepareStorageToApplyChangesUnderGivenConfig(
DataTypes.DelegatedExecutorsConfig storage _delegatedExecutorsConfig,
uint64 configNumber,
bool switchToGivenConfig
) private returns (uint64, bool) {
) private returns (bool) {
uint64 nextAvailableConfigNumber = _delegatedExecutorsConfig.maxConfigNumberSet + 1;
if (configNumber > nextAvailableConfigNumber) {
revert Errors.InvalidParameter();
@@ -543,6 +534,6 @@ library GeneralLib {
_delegatedExecutorsConfig.configNumber = configNumber;
}
}
return (configNumber, configSwitched);
return configSwitched;
}
}