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);
}
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;
}
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);
}
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);
}
}
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;
}
Aggregations