Skip to content

Commit

Permalink
CAPP-10752 Delete documents before deleting alias (#2)
Browse files Browse the repository at this point in the history
* CAPP-10752 Remove alias only after removing from documents
* CAPP-10752 Test destructive delete with a document attached to the alias
  • Loading branch information
avivmu authored and yanivmn committed Dec 23, 2018
1 parent f2c6e72 commit 6424e74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class AliasServiceImpl implements AliasService {
@Inject
private DocumentService documentService;

@Override
public List<Alias> addAll(PushApplication pushApplication, List<Alias> aliases, boolean oauth2) {
logger.debug("OAuth2 flag is: " + oauth2);
List<Alias> aliasList = new ArrayList<>();
Expand Down Expand Up @@ -99,17 +100,15 @@ public List<UserKey> remove(UUID pushApplicationId, UUID userId, boolean destruc
}

private List<UserKey> remove(UUID pushApplicationId, String alias, boolean destructive) {
// Remove any aliases belong to user_id
List<UserKey> removed = aliasDao.remove(pushApplicationId, alias);
// TODO - Remove from cluster cache

// TODO - Remove from cluster cache
if (destructive) {
// Remove user from keyCloak
keycloakService.delete(alias);

documentService.delete(pushApplicationId, find(pushApplicationId.toString(), alias));
}
return removed;
// Remove any aliases belong to user_id
return aliasDao.remove(pushApplicationId, alias);
}

@Override
Expand Down Expand Up @@ -142,6 +141,7 @@ public boolean registered(String alias) {
* @param alias alias name
* @param fqdn domain / team name.
*/
@Override
public Associated associated(String alias, String fqdn) {
PushApplication pushApplication = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.jboss.aerogear.unifiedpush.api.Alias;
import org.jboss.aerogear.unifiedpush.api.PushApplication;
import org.jboss.aerogear.unifiedpush.api.document.DocumentMetadata;
import org.jboss.aerogear.unifiedpush.service.annotations.LoggedInUser;
import org.jboss.aerogear.unifiedpush.service.impl.AliasServiceImpl.Associated;
import org.jboss.aerogear.unifiedpush.service.impl.spring.OAuth2Configuration;
Expand All @@ -40,6 +41,8 @@ public class AliasServiceTest extends AbstractCassandraServiceTest {

@Inject
private AliasService aliasService;
@Inject
private DocumentService documentService;

@Test
@Transactional
Expand Down Expand Up @@ -104,7 +107,8 @@ public void testRemoveAlias() throws IOException {
PushApplication pushApplication = new PushApplication();
UUID pushAppId = UUID.fromString(pushApplication.getPushApplicationID());

Alias[] legacyAliases = new Alias[] { new Alias(pushAppId, UUIDs.timeBased(), "Supprot@AeroGear.org"),
UUID firstGuid = UUIDs.timeBased();
Alias[] legacyAliases = new Alias[] { new Alias(pushAppId, firstGuid, "Supprot@AeroGear.org"),
new Alias(pushAppId, UUIDs.timeBased(), "Test@AeroGear.org"),
new Alias(pushAppId, UUIDs.timeBased(), "Help@AeroGear.org") };
List<Alias> aliasList = Arrays.asList(legacyAliases);
Expand All @@ -117,11 +121,14 @@ public void testRemoveAlias() throws IOException {
assertThat(aliasService.find(alias.getPushApplicationId(), alias.getId())).isNotNull();
});

documentService.save(new DocumentMetadata(pushAppId, getClass().getSimpleName(), firstGuid),
"doc1", "test_id");

// Delete alias
aliasService.remove(pushAppId, legacyAliases[0].getEmail());
aliasService.remove(pushAppId, firstGuid, true);

// Validate Alias is missing
assertThat(aliasService.find(legacyAliases[0].getPushApplicationId(), legacyAliases[0].getId())).isNull();
assertThat(aliasService.find(pushAppId, firstGuid)).isNull();

}

Expand Down

0 comments on commit 6424e74

Please sign in to comment.