Skip to content

Commit

Permalink
NOJIRA
Browse files Browse the repository at this point in the history
Wipeout will clear data and reset users and groups
  • Loading branch information
chasegawa authored and Bill Smith committed Sep 16, 2021
1 parent 3214fff commit 39d4956
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.springframework.transaction.annotation.Transactional
import javax.annotation.PostConstruct

@Component
@Profile('dev')
@Profile(['dev','very-dangerous'])
class DevConfig {
private final EntityDescriptorRepository entityDescriptorRepository
private final GroupsRepository groupsRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package edu.internet2.tier.shibboleth.admin.ui.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.internet2.tier.shibboleth.admin.ui.configuration.DevConfig;
import edu.internet2.tier.shibboleth.admin.ui.repository.EntityDescriptorRepository;
import edu.internet2.tier.shibboleth.admin.ui.repository.FilterRepository;
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository;
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolversPositionOrderContainerRepository;
import edu.internet2.tier.shibboleth.admin.ui.security.repository.GroupsRepository;
import edu.internet2.tier.shibboleth.admin.ui.security.repository.OwnershipRepository;
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository;
import edu.internet2.tier.shibboleth.admin.ui.security.service.IGroupService;
import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "/api/heheheheheheheWipeout")
@Profile("very-dangerous")
@Slf4j
public class DangerController {
@Autowired
DevConfig devConfig;

@Autowired
private EntityDescriptorService entityDescriptorService;

Expand All @@ -33,6 +38,9 @@ public class DangerController {

@Autowired
private IGroupService groupService;

@Autowired
private GroupsRepository groupRepository;

@Autowired
private MetadataResolverRepository metadataResolverRepository;
Expand All @@ -42,6 +50,9 @@ public class DangerController {

@Autowired
private OwnershipRepository ownershipRepository;

@Autowired
UserRepository userRepository;

@Transactional
@GetMapping
Expand All @@ -60,6 +71,22 @@ public ResponseEntity<?> wipeOut() {
this.metadataResolverRepository.deleteAll();
this.filterRepository.deleteAll();
this.metadataResolversPositionOrderContainerRepository.deleteAll();

clearUsersAndGroups();

return ResponseEntity.ok("yes, you did it");
}
}

private void clearUsersAndGroups() {
groupRepository.deleteAll();
ownershipRepository.clearAllOwnedByGroup();
userRepository.findAll().forEach(user -> {
ownershipRepository.deleteEntriesForOwnedObject(user); // Anything that owns the user that wasn't a group?
// users don't own things yet, so there isn't a method for deleting entries where they would, but may need that someday
userRepository.delete(user);
});

groupService.ensureAdminGroupExists();
devConfig.createDevUsersAndGroups();
}
}

0 comments on commit 39d4956

Please sign in to comment.