update contracts

main
cyl19970726 2 years ago
parent c87060c0dd
commit 89474b69c8

@ -88,7 +88,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
return false; return false;
} }
function roleToMembers(bytes32 role) public view returns(address[] memory members){ function getMembersByRole(bytes32 role) public view returns(address[] memory members){
uint256 count = getRoleMemberCount(role); uint256 count = getRoleMemberCount(role);
members = new address[](count); members = new address[](count);
for (uint i = 0; i < count; i++){ for (uint i = 0; i < count; i++){
@ -96,6 +96,12 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
} }
} }
function getAllMembers() public view returns(address[] memory admins,address[] memory managers,address[] memory cons ){
admins = getMembersByRole(DEFAULT_ADMIN_ROLE);
managers = getMembersByRole(MANAGER);
cons = getMembersByRole(CONTRIBUTOR);
}
function addManager(address member) public { function addManager(address member) public {
grantRole(MANAGER, member); grantRole(MANAGER, member);
} }
@ -120,8 +126,11 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
// ===== repository operator functions====== // ===== repository operator functions======
function repoList() public view returns(bytes[] memory rn){ function repoList() public view returns(string[] memory rn){
return repoNames; rn = new string[](repoNames.length);
for (uint i = 0; i <repoNames.length;i++){
rn[i] = string(repoNames[i]);
}
} }
//createRepository can be invoked by anyone within Hub //createRepository can be invoked by anyone within Hub
@ -178,6 +187,13 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
function isRepoMembership( function isRepoMembership(
bytes memory repoName, bytes memory repoName,
address member address member
) public view returns (bool) {
return _isRepoMembership(repoName,member);
}
function _isRepoMembership(
bytes memory repoName,
address member
) internal view returns (bool) { ) internal view returns (bool) {
RepositoryInfo storage repo = nameToRepository[repoName]; RepositoryInfo storage repo = nameToRepository[repoName];
if (repo.owner == member) return true; if (repo.owner == member) return true;
@ -219,7 +235,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
bytes memory branchPath, bytes memory branchPath,
bytes20 refHash bytes20 refHash
) external { ) external {
require(isRepoMembership(repoName, _msgSender())); require(_isRepoMembership(repoName, _msgSender()));
nameToRepository[repoName].branchs.updateBranch( nameToRepository[repoName].branchs.updateBranch(
repoName, repoName,
branchPath, branchPath,
@ -239,7 +255,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
bytes memory repoName, bytes memory repoName,
bytes memory branchPath bytes memory branchPath
) external { ) external {
require(isRepoMembership(repoName, _msgSender())); require(_isRepoMembership(repoName, _msgSender()));
nameToRepository[repoName].branchs.removeBranch(repoName, branchPath); nameToRepository[repoName].branchs.removeBranch(repoName, branchPath);
} }

Loading…
Cancel
Save