Search in sources :

Example 1 with DecisionMaker

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);
}
Also used : WantToContributeNotification(org.collectiveone.modules.activity.WantToContributeNotification) PostResult(org.collectiveone.common.dto.PostResult) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker) AppUser(org.collectiveone.modules.users.AppUser) Transactional(javax.transaction.Transactional)

Example 2 with DecisionMaker

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;
}
Also used : TokenType(org.collectiveone.modules.tokens.TokenType) NewInitiativeDto(org.collectiveone.modules.initiatives.dto.NewInitiativeDto) InitiativeDto(org.collectiveone.modules.initiatives.dto.InitiativeDto) MemberDto(org.collectiveone.modules.initiatives.dto.MemberDto) InitiativeMembersDto(org.collectiveone.modules.initiatives.dto.InitiativeMembersDto) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker)

Example 3 with DecisionMaker

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", "");
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker)

Example 4 with DecisionMaker

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;
}
Also used : MemberDto(org.collectiveone.modules.initiatives.dto.MemberDto) DecisionMaker(org.collectiveone.modules.governance.DecisionMaker) Transactional(javax.transaction.Transactional)

Aggregations

DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)4 Transactional (javax.transaction.Transactional)2 PostResult (org.collectiveone.common.dto.PostResult)2 MemberDto (org.collectiveone.modules.initiatives.dto.MemberDto)2 WantToContributeNotification (org.collectiveone.modules.activity.WantToContributeNotification)1 InitiativeDto (org.collectiveone.modules.initiatives.dto.InitiativeDto)1 InitiativeMembersDto (org.collectiveone.modules.initiatives.dto.InitiativeMembersDto)1 NewInitiativeDto (org.collectiveone.modules.initiatives.dto.NewInitiativeDto)1 TokenType (org.collectiveone.modules.tokens.TokenType)1 AppUser (org.collectiveone.modules.users.AppUser)1