use of org.collectiveone.modules.governance.DecisionMaker in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method wantToContribute.
@Transactional
public PostResult wantToContribute(UUID initiativeId, UUID userId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
AppUser user = appUserRepository.findByC1Id(userId);
List<DecisionMaker> admins = decisionMakerRepository.findByGovernance_IdAndRole(initiative.getGovernance().getId(), DecisionMakerRole.ADMIN);
for (DecisionMaker admin : admins) {
WantToContributeNotification notification = new WantToContributeNotification();
notification.setInitiative(initiative);
notification.setAdmin(admin.getUser());
notification.setUser(user);
notification.setEmailState(NotificationEmailState.PENDING);
wantToContributeRepository.save(notification);
}
return new PostResult("success", "notifications recorded for sending", null);
}
use of org.collectiveone.modules.governance.DecisionMaker in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method getMembersAndSubmembers.
public InitiativeMembersDto getMembersAndSubmembers(UUID initiativeId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
InitiativeMembersDto initiativeMembers = new InitiativeMembersDto();
initiativeMembers.setInitiativeId(initiative.getId().toString());
initiativeMembers.setInitiativeName(initiative.getMeta().getName());
List<TokenType> tokenTypes = tokenService.getTokenTypesHeldBy(initiative.getId());
/* add members of this initiative */
for (Member member : initiative.getMembers()) {
MemberDto memberDto = new MemberDto();
memberDto.setId(member.getId().toString());
memberDto.setUser(member.getUser().toDtoLight());
/* governance related data */
DecisionMaker decisionMaker = governanceService.getDecisionMaker(initiative.getGovernance().getId(), member.getUser().getC1Id());
if (decisionMaker != null) {
memberDto.setRole(decisionMaker.getRole().toString());
} else {
memberDto.setRole(DecisionMakerRole.MEMBER.toString());
}
/* assets related data */
for (TokenType token : tokenTypes) {
memberDto.getReceivedAssets().add(tokenService.getTokensOfHolderDtoLight(token.getId(), member.getUser().getC1Id()));
}
initiativeMembers.getMembers().add(memberDto);
}
/* add the members of all sub-initiatives too */
for (InitiativeDto subInitiative : getSubinitiativesTree(initiative.getId(), null)) {
/* recursively call with subinitiatives */
initiativeMembers.getSubinitiativesMembers().add(getMembersAndSubmembers(UUID.fromString(subInitiative.getId())));
}
return initiativeMembers;
}
use of org.collectiveone.modules.governance.DecisionMaker in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method deleteMember.
public PostResult deleteMember(UUID initiativeId, UUID memberUserId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
Member member = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, memberUserId);
List<DecisionMaker> admins = governanceService.getDecisionMakerWithRole(initiative.getGovernance().getId(), DecisionMakerRole.ADMIN);
boolean otherAdmin = false;
for (DecisionMaker admin : admins) {
if (!admin.getUser().getC1Id().equals(memberUserId)) {
otherAdmin = true;
}
}
if (otherAdmin) {
/* delete only if another admin remains */
/* members were subscribed to initiatives by default, so, delete them when deleting the member */
activityService.removeSubscriber(initiativeId, member.getUser().getC1Id());
memberRepository.delete(member);
governanceService.deleteDecisionMaker(initiative.getGovernance().getId(), member.getUser().getC1Id());
return new PostResult("success", "contributor deleted", "");
}
return new PostResult("error", "user is the only admin, it cannot be deleted", "");
}
use of org.collectiveone.modules.governance.DecisionMaker in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method getMember.
@Transactional
public MemberDto getMember(UUID initiativeId, UUID userId) {
if (userId == null) {
return null;
}
/* check in this initiative */
Initiative initiative = initiativeRepository.findById(initiativeId);
Member member = memberRepository.findByInitiative_IdAndUser_C1Id(initiativeId, userId);
MemberDto memberDto = new MemberDto();
if (member != null) {
memberDto.setId(member.getId().toString());
memberDto.setUser(member.getUser().toDtoLight());
/* governance related data */
DecisionMaker decisionMaker = governanceService.getDecisionMaker(initiative.getGovernance().getId(), member.getUser().getC1Id());
if (decisionMaker != null) {
memberDto.setRole(decisionMaker.getRole().toString());
} else {
memberDto.setRole(DecisionMakerRole.MEMBER.toString());
}
} else {
memberDto.setId("");
memberDto.setUser(appUserRepository.findByC1Id(userId).toDtoLight());
memberDto.setRole(DecisionMakerRole.ALIEN.toString());
}
return memberDto;
}
Aggregations