Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.22.0] - 2023-03-30

- Adds Support for Dashboard Search

## [2.21.0] - 2023-03-27

- Introduce TOTP Recipe plugin interface
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "2.21.0"
version = "2.22.0"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.dashboard.DashboardSearchTags;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;

import javax.annotation.Nonnull;
Expand All @@ -29,7 +30,7 @@ public interface AuthRecipeStorage extends Storage {
long getUsersCount(@Nullable RECIPE_ID[] includeRecipeIds) throws StorageQueryException;

AuthRecipeUserInfo[] getUsers(@Nonnull Integer limit, @Nonnull String timeJoinedOrder,
@Nullable RECIPE_ID[] includeRecipeIds, @Nullable String userId, @Nullable Long timeJoined)
@Nullable RECIPE_ID[] includeRecipeIds, @Nullable String userId, @Nullable Long timeJoined, @Nullable DashboardSearchTags dashboardSearchTags)
throws StorageQueryException;

boolean doesUserIdExist(String userId) throws StorageQueryException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package io.supertokens.pluginInterface.dashboard;

import java.util.ArrayList;

import javax.annotation.Nullable;

public class DashboardSearchTags {

public ArrayList<String> emails;
public ArrayList<String> phoneNumbers;
public ArrayList<String> providers;

public DashboardSearchTags(@Nullable ArrayList<String> emails, @Nullable ArrayList<String> phones,
@Nullable ArrayList<String> providers) {
this.emails = emails;
this.phoneNumbers = phones;
this.providers = providers;
}

public boolean shouldEmailPasswordTableBeSearched() {

ArrayList<SUPPORTED_SEARCH_TAGS> nonNullSearchTags = getNonNullSearchFields();
return nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.EMAIL) && nonNullSearchTags.size() == 1;

}

public boolean shouldThirdPartyTableBeSearched() {

ArrayList<SUPPORTED_SEARCH_TAGS> nonNullSearchTags = getNonNullSearchFields();
if(nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.EMAIL) && nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.PROVIDER)){
return nonNullSearchTags.size() == 2;
}

if(nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.EMAIL) || nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.PROVIDER)){
return nonNullSearchTags.size() == 1;
}

return false;
}

public boolean shouldPasswordlessTableBeSearched() {
ArrayList<SUPPORTED_SEARCH_TAGS> nonNullSearchTags = getNonNullSearchFields();
if(nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.EMAIL) && nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.PHONE)){
return nonNullSearchTags.size() == 2;
}

if(nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.EMAIL) || nonNullSearchTags.contains(SUPPORTED_SEARCH_TAGS.PHONE)){
return nonNullSearchTags.size() == 1;
}

return false;
}

private ArrayList<SUPPORTED_SEARCH_TAGS> getNonNullSearchFields() {
ArrayList<SUPPORTED_SEARCH_TAGS> nonNullSearchTags = new ArrayList<>();

if (this.emails != null) {
nonNullSearchTags.add(SUPPORTED_SEARCH_TAGS.EMAIL);
}

if (this.phoneNumbers != null) {
nonNullSearchTags.add(SUPPORTED_SEARCH_TAGS.PHONE);
}

if (this.providers != null) {
nonNullSearchTags.add(SUPPORTED_SEARCH_TAGS.PROVIDER);
}

return nonNullSearchTags;
}

public enum SUPPORTED_SEARCH_TAGS {
EMAIL("email"), PHONE("phone"), PROVIDER("provider");

private String tag;

SUPPORTED_SEARCH_TAGS(String tag) {
this.tag = tag;
}

public static SUPPORTED_SEARCH_TAGS fromString(String text) {
for (SUPPORTED_SEARCH_TAGS t : SUPPORTED_SEARCH_TAGS.values()) {
if (t.tag.equalsIgnoreCase(text)) {
return t;
}
}
return null;
}

@Override
public String toString() {
return tag;
}
}

}