Skip to content

Commit

Permalink
Support CRUD user/conversation settings in servers
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChenX committed Jun 1, 2024
1 parent 319c6b0 commit a30dbec
Show file tree
Hide file tree
Showing 59 changed files with 3,040 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<icu4j.version>74.2</icu4j.version>
<jctools-core.version>4.0.3</jctools-core.version>
<log4j.version>2.23.1</log4j.version>
<protobuf.version>4.26.1</protobuf.version>
<protobuf.version>4.27.0</protobuf.version>
<swagger.version>2.2.20</swagger.version>
<swagger-ui.version>5.11.10</swagger-ui.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.CREATE_MESSAGE_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.CREATE_RELATIONSHIP_GROUP_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.CREATE_RELATIONSHIP_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_CONVERSATION_SETTINGS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_GROUP_BLOCKED_USER_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_GROUP_INVITATION_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_GROUP_JOIN_QUESTIONS_REQUEST;
Expand All @@ -50,7 +51,9 @@
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_RELATIONSHIP_GROUP_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_RELATIONSHIP_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_RESOURCE_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.DELETE_USER_SETTINGS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_CONVERSATIONS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_CONVERSATION_SETTINGS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_FRIEND_REQUESTS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_GROUPS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_GROUP_BLOCKED_USER_IDS_REQUEST;
Expand All @@ -72,7 +75,9 @@
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_RESOURCE_UPLOAD_INFO_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_USER_ONLINE_STATUSES_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_USER_PROFILES_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.QUERY_USER_SETTINGS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_CONVERSATION_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_CONVERSATION_SETTINGS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_FRIEND_REQUEST_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_GROUP_INVITATION_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_GROUP_JOIN_QUESTION_REQUEST;
Expand All @@ -89,6 +94,7 @@
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_USER_LOCATION_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_USER_ONLINE_STATUS_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_USER_REQUEST;
import static im.turms.server.common.access.client.dto.request.TurmsRequest.KindCase.UPDATE_USER_SETTINGS_REQUEST;

/**
* @author James Chen
Expand All @@ -104,6 +110,8 @@ public enum PolicyStatementResource {
Set.of(UPDATE_USER_ONLINE_STATUS_REQUEST), Set.of(QUERY_USER_ONLINE_STATUSES_REQUEST)),
USER_PROFILE(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(),
Set.of(QUERY_USER_PROFILES_REQUEST)),
USER_SETTING(Collections.emptySet(), Set.of(DELETE_USER_SETTINGS_REQUEST),
Set.of(UPDATE_USER_SETTINGS_REQUEST), Set.of(QUERY_USER_SETTINGS_REQUEST)),
NEARBY_USER(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(),
Set.of(QUERY_NEARBY_USERS_REQUEST)),
// endregion
Expand Down Expand Up @@ -147,6 +155,9 @@ public enum PolicyStatementResource {
// region conversation
CONVERSATION(Collections.emptySet(), Collections.emptySet(),
Set.of(UPDATE_CONVERSATION_REQUEST), Set.of(QUERY_CONVERSATIONS_REQUEST)),
CONVERSATION_SETTING(Collections.emptySet(), Set.of(DELETE_CONVERSATION_SETTINGS_REQUEST),
Set.of(UPDATE_CONVERSATION_SETTINGS_REQUEST),
Set.of(QUERY_CONVERSATION_SETTINGS_REQUEST)),
// endregion
// region typing status
TYPING_STATUS(Collections.emptySet(), Collections.emptySet(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public boolean updateGlobalProperties(TurmsProperties properties) {
"Refused an illegal operation that tried to enable the previously disabled password-based identity and access management, "
+ "because "
+ "\"turms.gateway.session.identity-access-management.enabled\" is false, or "
+ "\"turms.gateway.session.identity-access-management.type\" is not \"password\" at startup. "
+ "\"turms.gateway.session.identity-access-management.type\" is not \"password\" on startup. "
+ "To enable it, you need to update the \"turms.gateway.session.identity-access-management.enabled\" setting to true and restart the server");
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ public enum ResponseStatusCode {
403),
NOT_FRIEND_TO_SEND_TYPING_STATUS(4102, "Only friends can send their typing status", 403),

// Conversation - Setting
NOT_RELATED_USER_TO_UPDATE_PRIVATE_CONVERSATION_SETTING(4200,
"Only the related user can update the private conversation setting", 403),
NOT_GROUP_MEMBER_TO_UPDATE_GROUP_CONVERSATION_SETTING(4201,
"Only the group member can update the group conversation setting", 403),

// Message

// Message - Send
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ public Flux<T> findByIds(Collection<K> ids) {
return mongoClient.findMany(entityClass, filter);
}

public Flux<String> findObjectFieldsById(
K id,
String parentField,
Collection<String> includedFields) {
Filter filter = Filter.newBuilder(1)
.eq(DomainFieldName.ID, id);
return mongoClient.findObjectFields(entityClass, filter, parentField, includedFields);
}

public Flux<ChangeStreamDocument<T>> watch(FullDocument fullDocument) {
return mongoClient.watch(entityClass, fullDocument);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package im.turms.server.common.infra.collection;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -662,6 +663,14 @@ public static <T> Set<T> union(Collection<Set<T>> collections) {
return set;
}

public static BitSet newBitSet(byte[] bytes) {
BitSet set = new BitSet(bytes.length);
for (byte b : bytes) {
set.set(b);
}
return set;
}

// endregion

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* limitations under the License.
*/

package im.turms.server.common.infra.property.constant;
package im.turms.server.common.infra.lang;

/**
* @author James Chen
*/
public enum PasswordType {
public enum StringPattern {
NUMERIC,
ALPHABETIC,
ALPHANUMERIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
Expand Down Expand Up @@ -750,4 +751,23 @@ public static float findSimilarity(String x, String y) {
return 1.0F - distance / (float) maxLength;
}

public static boolean allCharsInSet(String string, BitSet set) {
byte coder = getCoder(string);
if (LATIN1 == coder) {
byte[] bytes = getBytes(string);
for (byte b : bytes) {
if (!set.get(b)) {
return false;
}
}
return true;
}
int length = string.length();
for (int i = 0; i < length; i++) {
if (!set.get(string.charAt(i))) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import jakarta.validation.constraints.Size;

import im.turms.server.common.infra.validation.LessThanOrEqualTo;
import im.turms.server.common.infra.validation.MatchesStringPattern;
import im.turms.server.common.infra.validation.ValidCron;
import im.turms.server.common.infra.validation.ValidRegex;

/**
* @author James Chen
Expand All @@ -33,23 +35,29 @@ public record PropertyConstraints(
long max,
@Nullable String lessThanOrEqualTo,
@Nullable Size size,
@Nullable ValidCron validCron
@Nullable ValidCron validCron,
@Nullable ValidRegex validRegex,
@Nullable MatchesStringPattern matchesStringPattern
) {

public static final PropertyConstraints NULL =
new PropertyConstraints(Long.MIN_VALUE, Long.MAX_VALUE, null, null, null);
new PropertyConstraints(Long.MIN_VALUE, Long.MAX_VALUE, null, null, null, null, null);

public static PropertyConstraints of(
@Nullable Min min,
@Nullable Max max,
@Nullable LessThanOrEqualTo lessThanOrEqualTo,
@Nullable Size size,
@Nullable ValidCron validCron) {
@Nullable ValidCron validCron,
@Nullable ValidRegex validRegex,
@Nullable MatchesStringPattern matchesStringPattern) {
if (min == null
&& max == null
&& lessThanOrEqualTo == null
&& size == null
&& validCron == null) {
&& validCron == null
&& validRegex == null
&& matchesStringPattern == null) {
return NULL;
}
return new PropertyConstraints(
Expand All @@ -63,7 +71,9 @@ public static PropertyConstraints of(
? null
: lessThanOrEqualTo.value(),
size,
validCron);
validCron,
validRegex,
matchesStringPattern);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
import im.turms.server.common.infra.security.SensitiveProperty;
import im.turms.server.common.infra.serialization.SerializationException;
import im.turms.server.common.infra.validation.LessThanOrEqualTo;
import im.turms.server.common.infra.validation.MatchesStringPattern;
import im.turms.server.common.infra.validation.ValidCron;
import im.turms.server.common.infra.validation.ValidRegex;

import static im.turms.server.common.infra.json.JsonCodecPool.MAPPER;

Expand Down Expand Up @@ -163,7 +165,9 @@ private static void collectFieldInfos(
field.getDeclaredAnnotation(Max.class),
field.getDeclaredAnnotation(LessThanOrEqualTo.class),
field.getDeclaredAnnotation(Size.class),
field.getDeclaredAnnotation(ValidCron.class));
field.getDeclaredAnnotation(ValidCron.class),
field.getDeclaredAnnotation(ValidRegex.class),
field.getDeclaredAnnotation(MatchesStringPattern.class));
propertyFieldInfos.add(new PropertyFieldInfo(
field,
VarAccessorFactory.get(field),
Expand Down Expand Up @@ -232,4 +236,4 @@ private static String getTypeName(Class<?> type) {
return type.getTypeName();
}

}
}
Loading

0 comments on commit a30dbec

Please sign in to comment.