Skip to content

Commit

Permalink
Merge pull request #514 from hackdays-io/revert-513-feature/change-owner
Browse files Browse the repository at this point in the history
Revert "Feature/change owner"
  • Loading branch information
yu23ki14 authored Feb 7, 2024
2 parents 6f9742f + 290b363 commit a9d3080
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 146 deletions.
17 changes: 0 additions & 17 deletions frontend/src/components/molecules/EventGroupTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const EventGroupTab: FC<Props> = ({ group }) => {
return 1;
case router.asPath.includes("role"):
return 2;
case router.asPath.includes("transfer"):
return 3;
default:
break;
}
Expand Down Expand Up @@ -83,21 +81,6 @@ const EventGroupTab: FC<Props> = ({ group }) => {
{t.RBAC_EDIT_COLLABORATORS}
</Tab>
)}
{(group.ownerAddress === address) && (
<Tab
_selected={{
borderColor: "mintGreen.300",
borderWidth: 1,
borderBottom: "none",
backgroundColor: "mintGreen.50",
}}
onClick={() =>
router.push(`/event-groups/${router.query.eventgroupid}/transfer`)
}
>
{t.EVENT_GROUP_TAB_TRANSFER}
</Tab>
)}
</TabList>
</Tabs>
);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default {
// Event group tab
EVENT_GROUP_TAB_EVENTS: "Event List",
EVENT_GROUP_TAB_LEADERS: "Leader Board",
EVENT_GROUP_TAB_TRANSFER: "Transfer Owner",
// Event group leaders
EVENT_GROUP_LEADERS_RANK: "RANK",
EVENT_GROUP_LEADERS_ADDRESS: "ADDRESS",
Expand Down
1 change: 0 additions & 1 deletion frontend/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default {
// Event group tab
EVENT_GROUP_TAB_EVENTS: "イベント一覧",
EVENT_GROUP_TAB_LEADERS: "リーダーボード",
EVENT_GROUP_TAB_TRANSFER: "権限譲与",
// Event group leaders
EVENT_GROUP_LEADERS_RANK: "ランク",
EVENT_GROUP_LEADERS_ADDRESS: "アドレス",
Expand Down
47 changes: 1 addition & 46 deletions hardhat/contracts/Event.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ contract EventManager is OwnableUpgradeable {
private memberRolesByGroupId;
mapping(uint256 => address[]) private memberAddressesByGroupId;

modifier onlyGroupOwner(uint256 _groupId) {
require(_isGroupOwner(_groupId, msg.sender), "You have no permission");
_;
}

modifier onlyAdminAccess(uint256 _groupId) {
require(
_hasAdminAccess(_groupId, msg.sender),
Expand Down Expand Up @@ -121,11 +116,6 @@ contract EventManager is OwnableUpgradeable {

event CreateGroup(address indexed owner, uint256 groupId);
event CreateEvent(address indexed owner, uint256 eventId);
event TransferGroupOwner(
address indexed prevOwner,
address indexed newOwner,
uint256 groupId
);

// Currently, reinitializer(3) was executed as constructor.
function initialize(
Expand Down Expand Up @@ -204,41 +194,6 @@ contract EventManager is OwnableUpgradeable {
return _groups;
}

function transferGroupOwner(
uint256 _groupId,
address _newOwnerAddress
) external whenNotPaused onlyGroupOwner(_groupId) {
require(_newOwnerAddress != address(0), "New owner address is blank");

for (uint256 i = 0; i < groups.length; i++) {
if (groups[i].groupId == _groupId) {
groups[i].ownerAddress = _newOwnerAddress;
break;
}
}

ownGroupIds[_newOwnerAddress].push(_groupId);

for (uint256 i = 0; i < ownGroupIds[msg.sender].length; i++) {
if (ownGroupIds[msg.sender][i] == _groupId) {
ownGroupIds[msg.sender][i] = ownGroupIds[msg.sender][
ownGroupIds[msg.sender].length - 1
];
ownGroupIds[msg.sender].pop();
break;
}
}

emit TransferGroupOwner(msg.sender, _newOwnerAddress, _groupId);
}

function _isGroupOwner(
uint256 _groupId,
address _address
) private view returns (bool) {
return groups[_groupId - 1].ownerAddress == _address;
}

function createEventRecord(
uint256 _groupId,
string memory _name,
Expand Down Expand Up @@ -442,7 +397,7 @@ contract EventManager is OwnableUpgradeable {
require(_groupId > 0 && _groupId <= groups.length, "Invalid groupId");

return
_isGroupOwner(_groupId, _address) ||
groups[_groupId - 1].ownerAddress == _address ||
_hasRole(_groupId, _address, ADMIN_ROLE);
}

Expand Down
87 changes: 6 additions & 81 deletions hardhat/test/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ describe("EventManager", function () {
let participant1: SignerWithAddress;
let participant2: SignerWithAddress;
let relayer: SignerWithAddress;
let newOwner: SignerWithAddress;

before(async () => {
[organizer, participant1, participant2, relayer, newOwner] =
[organizer, participant1, participant2, relayer] =
await ethers.getSigners();
const SecretPhraseVerifierFactory = await ethers.getContractFactory(
"SecretPhraseVerifier"
Expand Down Expand Up @@ -88,8 +87,7 @@ describe("EventManager", function () {
relayer.address,
250000,
1000000,
operationController.address,
],
operationController.address],
{
initializer: "initialize",
}
Expand Down Expand Up @@ -489,7 +487,7 @@ describe("EventManager", function () {
relayer.address,
500000,
1000000,
operationController.address,
operationController.address
],
{
initializer: "initialize",
Expand Down Expand Up @@ -544,7 +542,7 @@ describe("EventManager", function () {
relayer.address,
500000,
1000000,
operationController.address,
operationController.address
],
{
initializer: "initialize",
Expand Down Expand Up @@ -619,7 +617,7 @@ describe("EventManager", function () {
relayer.address,
250000,
1000000,
operationController.address,
operationController.address
],
{
initializer: "initialize",
Expand Down Expand Up @@ -700,79 +698,6 @@ describe("EventManager", function () {
});
});

describe("Transfer Owner", function () {
let eventManager: EventManager;
before(async () => {
const eventManagerContractFactory = await ethers.getContractFactory(
"EventManager"
);
const deployedEventManagerContract = await upgrades.deployProxy(
eventManagerContractFactory,
[
organizer.address,
relayer.address,
250000,
1000000,
operationController.address,
],
{ initializer: "initialize" }
);
eventManager = deployedEventManagerContract as EventManager;
await eventManager.deployed();
await eventManager.setMintNFTAddr(mintNFT.address);
await mintNFT.setEventManagerAddr(eventManager.address);

const createGroupTx = await eventManager
.connect(organizer)
.createGroup("transferGroup");
await createGroupTx.wait();

const createdGroups = await eventManager.getGroups();
expect(createdGroups.some((group) => group.name === "transferGroup")).to
.be.true;
});

it("Should transfer group ownership", async function () {
const groups = await eventManager.getGroups();
const group = groups.find((group) => group.name === "transferGroup");
const groupId = group!.groupId;

const transferTx = await eventManager
.connect(organizer)
.transferGroupOwner(groupId, newOwner.address);
await transferTx.wait();
expect(transferTx)
.to.emit(eventManager, "TransferOwner")
.withArgs(groupId, organizer.address, newOwner.address);

const updatedGroups = await eventManager.getGroups();
const updatedGroup = updatedGroups.find((group) =>
group.groupId.eq(groupId)
);

expect(updatedGroup, "Updated group not found").to.exist;
expect(updatedGroup!.ownerAddress).to.equal(newOwner.address);

const ownGroups = await eventManager.getOwnGroups(newOwner.address);
expect(ownGroups.some((group) => group.groupId.eq(groupId))).to.be.true;
const ownGroups2 = await eventManager.getOwnGroups(organizer.address);
expect(ownGroups2.every((group) => !group.groupId.eq(groupId))).to.be
.true;
});

it("Should revert if not group owner", async function () {
const groups = await eventManager.getGroups();
const group = groups.find((group) => group.name === "transferGroup");
const groupId = group!.groupId;

await expect(
eventManager
.connect(participant1)
.transferGroupOwner(groupId, newOwner.address)
).to.be.revertedWith("You have no permission");
});
});

describe("Role", async () => {
let eventManager: EventManager;

Expand All @@ -787,7 +712,7 @@ describe("EventManager", function () {
relayer.address,
250000,
1000000,
operationController.address,
operationController.address
],
{
initializer: "initialize",
Expand Down

0 comments on commit a9d3080

Please sign in to comment.