Search in sources :

Example 11 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.

the class RepositoryManager method addParticipants.

/**
 * add provided list of identities as participant to the repo entry. silently ignore
 * if some identities were already participant before.
 * @param ureqIdentity
 * @param addIdentities
 * @param re
 * @param userActivityLogger
 */
public void addParticipants(Identity ureqIdentity, Roles ureqRoles, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) {
    List<Identity> addIdentities = iae.getAddIdentities();
    List<Identity> reallyAddedId = new ArrayList<Identity>();
    for (Identity identityToAdd : addIdentities) {
        if (!repositoryEntryRelationDao.hasRole(identityToAdd, re, GroupRoles.participant.name())) {
            boolean mustAccept = true;
            if (ureqIdentity != null && ureqIdentity.equals(identityToAdd)) {
                // adding itself, we hope that he knows what he makes
                mustAccept = false;
            } else if (ureqRoles == null || ureqIdentity == null) {
                // administrative task
                mustAccept = false;
            } else {
                mustAccept = repositoryModule.isAcceptMembership(ureqRoles);
            }
            if (mustAccept) {
                ResourceReservation olderReservation = reservationDao.loadReservation(identityToAdd, re.getOlatResource());
                if (olderReservation == null) {
                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.MONTH, 6);
                    Date expiration = cal.getTime();
                    ResourceReservation reservation = reservationDao.createReservation(identityToAdd, "repo_participant", expiration, re.getOlatResource());
                    if (reservation != null) {
                        RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addParticipant, mailing);
                    }
                }
            } else {
                addInternalParticipant(ureqIdentity, identityToAdd, re);
                reallyAddedId.add(identityToAdd);
                RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addParticipant, mailing);
            }
        }
    }
    iae.setIdentitiesAddedEvent(reallyAddedId);
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 12 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.

the class RepositoryManager method removeMembers.

/**
 * Remove the identities as members of the repository and from
 * all connected business groups.
 *
 * @param members
 * @param re
 */
public boolean removeMembers(Identity ureqIdentity, List<Identity> members, RepositoryEntry re, MailPackage mailing) {
    // log the action
    ActionType actionType = ThreadLocalUserActivityLogger.getStickyActionType();
    ThreadLocalUserActivityLogger.setStickyActionType(ActionType.admin);
    for (Identity identity : members) {
        try {
            ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_MEMBER_REMOVED, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry), LoggingResourceable.wrap(identity));
        } finally {
            ThreadLocalUserActivityLogger.setStickyActionType(actionType);
        }
    }
    List<ResourceReservation> reservations = reservationDao.loadReservations(Collections.singletonList(re.getOlatResource()));
    for (ResourceReservation reservation : reservations) {
        if (members.contains(reservation.getIdentity())) {
            reservationDao.deleteReservation(reservation);
        }
    }
    boolean allOk = repositoryEntryRelationDao.removeMembers(re, members);
    if (allOk) {
        int count = 0;
        List<RepositoryEntryMembershipModifiedEvent> deferredEvents = new ArrayList<>();
        for (Identity identity : members) {
            deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(identity, re));
            if (++count % 100 == 0) {
                dbInstance.commitAndCloseSession();
            }
        }
        dbInstance.commit();
        sendDeferredEvents(deferredEvents, re);
    }
    if (allOk) {
        // do logging - not optimal but
        StringBuilder sb = new StringBuilder();
        sb.append("Identity(.key):").append(ureqIdentity.getKey()).append("removed multiple identities from security groups. Identities:: ");
        for (Identity member : members) {
            sb.append(member.getName()).append(", ");
        }
        log.audit(sb.toString());
    }
    for (Identity identity : members) {
        RepositoryMailing.sendEmail(ureqIdentity, identity, re, RepositoryMailing.Type.removeParticipant, mailing);
    }
    return allOk;
}
Also used : ActionType(org.olat.core.logging.activity.ActionType) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) RepositoryEntryMembershipModifiedEvent(org.olat.repository.model.RepositoryEntryMembershipModifiedEvent) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 13 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.

the class RepositoryManager method addTutors.

/**
 * add provided list of identities as tutor to the repo entry. silently ignore
 * if some identities were already tutor before.
 * @param ureqIdentity
 * @param addIdentities
 * @param re
 * @param userActivityLogger
 */
public void addTutors(Identity ureqIdentity, Roles ureqRoles, IdentitiesAddEvent iae, RepositoryEntry re, MailPackage mailing) {
    List<Identity> addIdentities = iae.getAddIdentities();
    List<Identity> reallyAddedId = new ArrayList<Identity>();
    for (Identity identityToAdd : addIdentities) {
        if (!repositoryEntryRelationDao.hasRole(identityToAdd, re, GroupRoles.coach.name())) {
            boolean mustAccept = true;
            if (ureqIdentity != null && ureqIdentity.equals(identityToAdd)) {
                // adding itself, we hope that he knows what he makes
                mustAccept = false;
            } else if (ureqRoles == null || ureqIdentity == null) {
                // administrative task
                mustAccept = false;
            } else {
                mustAccept = repositoryModule.isAcceptMembership(ureqRoles);
            }
            if (mustAccept) {
                ResourceReservation olderReservation = reservationDao.loadReservation(identityToAdd, re.getOlatResource());
                if (olderReservation == null) {
                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.MONTH, 6);
                    Date expiration = cal.getTime();
                    ResourceReservation reservation = reservationDao.createReservation(identityToAdd, "repo_tutors", expiration, re.getOlatResource());
                    if (reservation != null) {
                        RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addTutor, mailing);
                    }
                }
            } else {
                addInternalTutors(ureqIdentity, identityToAdd, re, reallyAddedId);
                RepositoryMailing.sendEmail(ureqIdentity, identityToAdd, re, RepositoryMailing.Type.addTutor, mailing);
            }
        }
    // else silently ignore already owner identities
    }
    iae.setIdentitiesAddedEvent(reallyAddedId);
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 14 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.

the class PaypalManagerImpl method completeDeniedTransaction.

private void completeDeniedTransaction(PaypalTransaction trx) {
    updateTransaction(trx, PaypalTransactionStatus.DENIED);
    Order order = orderManager.loadOrderByNr(trx.getRefNo());
    order = orderManager.save(order, OrderStatus.ERROR);
    PaypalAccessMethod method = getMethodSecure(trx.getMethodId());
    if (order.getKey().equals(trx.getOrderId())) {
        // make accessible
        Identity identity = order.getDelivery();
        for (OrderPart part : order.getParts()) {
            if (part.getKey().equals(trx.getOrderPartId())) {
                AccessTransaction transaction = transactionManager.createTransaction(order, part, method);
                transaction = transactionManager.update(transaction, AccessTransactionStatus.ERROR);
                for (OrderLine line : part.getOrderLines()) {
                    acService.denyAccesToResource(identity, line.getOffer());
                    log.audit("Paypal payed access revoked for: " + buildLogMessage(line, method) + " to " + identity, null);
                    ResourceReservation reservation = reservationDao.loadReservation(identity, line.getOffer().getResource());
                    if (reservation != null) {
                        acService.removeReservation(identity, identity, reservation);
                        log.audit("Remove reservation after cancellation for: " + reservation + " to " + identity, null);
                    }
                }
            }
        }
    } else {
        log.error("Order not in sync with PaypalTransaction", null);
    }
}
Also used : Order(org.olat.resource.accesscontrol.Order) AccessTransaction(org.olat.resource.accesscontrol.AccessTransaction) OrderLine(org.olat.resource.accesscontrol.OrderLine) ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) OrderPart(org.olat.resource.accesscontrol.OrderPart) Identity(org.olat.core.id.Identity) PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)

Example 15 with ResourceReservation

use of org.olat.resource.accesscontrol.ResourceReservation in project openolat by klemens.

the class BusinessGroupServiceImpl method addOwner.

private boolean addOwner(Identity ureqIdentity, Roles ureqRoles, Identity identityToAdd, BusinessGroup group, MailPackage mailing, List<BusinessGroupModifiedEvent.Deferred> events) {
    if (!businessGroupRelationDAO.hasRole(identityToAdd, group, GroupRoles.coach.name())) {
        boolean mustAccept = true;
        if (ureqIdentity != null && ureqIdentity.equals(identityToAdd)) {
            // adding itself, we hope that he knows what he makes
            mustAccept = false;
        } else if (ureqRoles == null || ureqIdentity == null) {
            // administrative task
            mustAccept = false;
        } else {
            mustAccept = groupModule.isAcceptMembership(ureqRoles);
        }
        if (mustAccept) {
            ResourceReservation olderReservation = reservationDao.loadReservation(identityToAdd, group.getResource());
            if (olderReservation == null) {
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.MONTH, 6);
                Date expiration = cal.getTime();
                ResourceReservation reservation = reservationDao.createReservation(identityToAdd, "group_coach", expiration, group.getResource());
                if (reservation != null) {
                    BusinessGroupMailing.sendEmail(ureqIdentity, identityToAdd, group, MailType.addCoach, mailing);
                    // logging
                    log.audit("Identity(.key):" + ureqIdentity.getKey() + " added identity '" + identityToAdd.getName() + "' to group with key " + group.getKey());
                }
            }
        } else {
            internalAddCoach(ureqIdentity, identityToAdd, group, events);
            BusinessGroupMailing.sendEmail(ureqIdentity, identityToAdd, group, MailType.addCoach, mailing);
        }
        return true;
    }
    return false;
}
Also used : ResourceReservation(org.olat.resource.accesscontrol.ResourceReservation) Calendar(java.util.Calendar) Date(java.util.Date)

Aggregations

ResourceReservation (org.olat.resource.accesscontrol.ResourceReservation)36 Identity (org.olat.core.id.Identity)24 Calendar (java.util.Calendar)20 BusinessGroup (org.olat.group.BusinessGroup)20 ArrayList (java.util.ArrayList)14 Date (java.util.Date)12 Test (org.junit.Test)10 OLATResource (org.olat.resource.OLATResource)8 BusinessGroupModifiedEvent (org.olat.group.ui.edit.BusinessGroupModifiedEvent)6 HashMap (java.util.HashMap)4 Order (org.olat.resource.accesscontrol.Order)4 OrderLine (org.olat.resource.accesscontrol.OrderLine)4 OrderPart (org.olat.resource.accesscontrol.OrderPart)4 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2 ActionType (org.olat.core.logging.activity.ActionType)2 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupShort (org.olat.group.BusinessGroupShort)2 BusinessGroupMembershipViewImpl (org.olat.group.model.BusinessGroupMembershipViewImpl)2 EnrollState (org.olat.group.model.EnrollState)2