mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Implement setting group permissions
This commit is contained in:
parent
7170a68571
commit
78f22c7020
7 changed files with 104 additions and 13 deletions
|
@ -25,6 +25,7 @@ import org.asamk.signal.manager.groups.GroupIdV1;
|
||||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||||
import org.asamk.signal.manager.groups.GroupLinkState;
|
import org.asamk.signal.manager.groups.GroupLinkState;
|
||||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||||
|
import org.asamk.signal.manager.groups.GroupPermission;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||||
import org.asamk.signal.manager.helper.GroupV2Helper;
|
import org.asamk.signal.manager.helper.GroupV2Helper;
|
||||||
|
@ -836,6 +837,8 @@ public class Manager implements Closeable {
|
||||||
List<String> removeAdmins,
|
List<String> removeAdmins,
|
||||||
boolean resetGroupLink,
|
boolean resetGroupLink,
|
||||||
GroupLinkState groupLinkState,
|
GroupLinkState groupLinkState,
|
||||||
|
GroupPermission addMemberPermission,
|
||||||
|
GroupPermission editDetailsPermission,
|
||||||
File avatarFile,
|
File avatarFile,
|
||||||
Integer expirationTimer
|
Integer expirationTimer
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||||
|
@ -848,6 +851,8 @@ public class Manager implements Closeable {
|
||||||
removeAdmins == null ? null : getSignalServiceAddresses(removeAdmins),
|
removeAdmins == null ? null : getSignalServiceAddresses(removeAdmins),
|
||||||
resetGroupLink,
|
resetGroupLink,
|
||||||
groupLinkState,
|
groupLinkState,
|
||||||
|
addMemberPermission,
|
||||||
|
editDetailsPermission,
|
||||||
avatarFile,
|
avatarFile,
|
||||||
expirationTimer);
|
expirationTimer);
|
||||||
}
|
}
|
||||||
|
@ -862,8 +867,10 @@ public class Manager implements Closeable {
|
||||||
final Set<RecipientId> removeAdmins,
|
final Set<RecipientId> removeAdmins,
|
||||||
final boolean resetGroupLink,
|
final boolean resetGroupLink,
|
||||||
final GroupLinkState groupLinkState,
|
final GroupLinkState groupLinkState,
|
||||||
|
final GroupPermission addMemberPermission,
|
||||||
|
final GroupPermission editDetailsPermission,
|
||||||
final File avatarFile,
|
final File avatarFile,
|
||||||
Integer expirationTimer
|
final Integer expirationTimer
|
||||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
var group = getGroupForUpdating(groupId);
|
var group = getGroupForUpdating(groupId);
|
||||||
|
|
||||||
|
@ -877,6 +884,8 @@ public class Manager implements Closeable {
|
||||||
removeAdmins,
|
removeAdmins,
|
||||||
resetGroupLink,
|
resetGroupLink,
|
||||||
groupLinkState,
|
groupLinkState,
|
||||||
|
addMemberPermission,
|
||||||
|
editDetailsPermission,
|
||||||
avatarFile,
|
avatarFile,
|
||||||
expirationTimer);
|
expirationTimer);
|
||||||
}
|
}
|
||||||
|
@ -948,6 +957,8 @@ public class Manager implements Closeable {
|
||||||
final Set<RecipientId> removeAdmins,
|
final Set<RecipientId> removeAdmins,
|
||||||
final boolean resetGroupLink,
|
final boolean resetGroupLink,
|
||||||
final GroupLinkState groupLinkState,
|
final GroupLinkState groupLinkState,
|
||||||
|
final GroupPermission addMemberPermission,
|
||||||
|
final GroupPermission editDetailsPermission,
|
||||||
final File avatarFile,
|
final File avatarFile,
|
||||||
Integer expirationTimer
|
Integer expirationTimer
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
|
@ -1020,6 +1031,16 @@ public class Manager implements Closeable {
|
||||||
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (addMemberPermission != null) {
|
||||||
|
var groupGroupChangePair = groupV2Helper.setAddMemberPermission(group, addMemberPermission);
|
||||||
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editDetailsPermission != null) {
|
||||||
|
var groupGroupChangePair = groupV2Helper.setEditDetailsPermission(group, editDetailsPermission);
|
||||||
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
|
}
|
||||||
|
|
||||||
if (expirationTimer != null) {
|
if (expirationTimer != null) {
|
||||||
var groupGroupChangePair = groupV2Helper.setMessageExpirationTimer(group, expirationTimer);
|
var groupGroupChangePair = groupV2Helper.setMessageExpirationTimer(group, expirationTimer);
|
||||||
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.asamk.signal.manager.groups;
|
||||||
|
|
||||||
|
public enum GroupPermission {
|
||||||
|
EVERY_MEMBER,
|
||||||
|
ONLY_ADMINS,
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
|
||||||
import org.asamk.signal.manager.groups.GroupLinkPassword;
|
import org.asamk.signal.manager.groups.GroupLinkPassword;
|
||||||
import org.asamk.signal.manager.groups.GroupLinkState;
|
import org.asamk.signal.manager.groups.GroupLinkState;
|
||||||
|
import org.asamk.signal.manager.groups.GroupPermission;
|
||||||
import org.asamk.signal.manager.groups.GroupUtils;
|
import org.asamk.signal.manager.groups.GroupUtils;
|
||||||
import org.asamk.signal.manager.storage.groups.GroupInfoV2;
|
import org.asamk.signal.manager.storage.groups.GroupInfoV2;
|
||||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||||
|
@ -314,6 +315,26 @@ public class GroupV2Helper {
|
||||||
return commitChange(groupInfoV2, change);
|
return commitChange(groupInfoV2, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pair<DecryptedGroup, GroupChange> setEditDetailsPermission(
|
||||||
|
GroupInfoV2 groupInfoV2, GroupPermission permission
|
||||||
|
) throws IOException {
|
||||||
|
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||||
|
|
||||||
|
final var accessRequired = toAccessControl(permission);
|
||||||
|
final var change = groupOperations.createChangeAttributesRights(accessRequired);
|
||||||
|
return commitChange(groupInfoV2, change);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pair<DecryptedGroup, GroupChange> setAddMemberPermission(
|
||||||
|
GroupInfoV2 groupInfoV2, GroupPermission permission
|
||||||
|
) throws IOException {
|
||||||
|
final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
|
||||||
|
|
||||||
|
final var accessRequired = toAccessControl(permission);
|
||||||
|
final var change = groupOperations.createChangeMembershipRights(accessRequired);
|
||||||
|
return commitChange(groupInfoV2, change);
|
||||||
|
}
|
||||||
|
|
||||||
public GroupChange joinGroup(
|
public GroupChange joinGroup(
|
||||||
GroupMasterKey groupMasterKey,
|
GroupMasterKey groupMasterKey,
|
||||||
GroupLinkPassword groupLinkPassword,
|
GroupLinkPassword groupLinkPassword,
|
||||||
|
@ -390,6 +411,17 @@ public class GroupV2Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AccessControl.AccessRequired toAccessControl(final GroupPermission permission) {
|
||||||
|
switch (permission) {
|
||||||
|
case EVERY_MEMBER:
|
||||||
|
return AccessControl.AccessRequired.MEMBER;
|
||||||
|
case ONLY_ADMINS:
|
||||||
|
return AccessControl.AccessRequired.ADMINISTRATOR;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private GroupsV2Operations.GroupOperations getGroupOperations(final GroupInfoV2 groupInfoV2) {
|
private GroupsV2Operations.GroupOperations getGroupOperations(final GroupInfoV2 groupInfoV2) {
|
||||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||||
return groupsV2Operations.forGroup(groupSecretParams);
|
return groupsV2Operations.forGroup(groupSecretParams);
|
||||||
|
|
27
src/main/java/org/asamk/signal/GroupPermission.java
Normal file
27
src/main/java/org/asamk/signal/GroupPermission.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package org.asamk.signal;
|
||||||
|
|
||||||
|
public enum GroupPermission {
|
||||||
|
EVERY_MEMBER {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "every-member";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ONLY_ADMINS {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "only-admins";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public org.asamk.signal.manager.groups.GroupPermission toManager() {
|
||||||
|
switch (this) {
|
||||||
|
case EVERY_MEMBER:
|
||||||
|
return org.asamk.signal.manager.groups.GroupPermission.EVERY_MEMBER;
|
||||||
|
case ONLY_ADMINS:
|
||||||
|
return org.asamk.signal.manager.groups.GroupPermission.ONLY_ADMINS;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ public class QuitGroupCommand implements LocalCommand {
|
||||||
try {
|
try {
|
||||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||||
} catch (GroupIdFormatException e) {
|
} catch (GroupIdFormatException e) {
|
||||||
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.GroupLinkState;
|
import org.asamk.signal.GroupLinkState;
|
||||||
|
import org.asamk.signal.GroupPermission;
|
||||||
import org.asamk.signal.PlainTextWriterImpl;
|
import org.asamk.signal.PlainTextWriterImpl;
|
||||||
import org.asamk.signal.commands.exceptions.CommandException;
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||||
|
@ -55,6 +56,13 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
.help("Set group link state, with or without admin approval")
|
.help("Set group link state, with or without admin approval")
|
||||||
.type(Arguments.enumStringType(GroupLinkState.class));
|
.type(Arguments.enumStringType(GroupLinkState.class));
|
||||||
|
|
||||||
|
subparser.addArgument("--set-permission-add-member")
|
||||||
|
.help("Set permission to add new group members")
|
||||||
|
.type(Arguments.enumStringType(GroupPermission.class));
|
||||||
|
subparser.addArgument("--set-permission-edit-details")
|
||||||
|
.help("Set permission to edit group details")
|
||||||
|
.type(Arguments.enumStringType(GroupPermission.class));
|
||||||
|
|
||||||
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,29 +75,22 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
try {
|
try {
|
||||||
groupId = Util.decodeGroupId(groupIdString);
|
groupId = Util.decodeGroupId(groupIdString);
|
||||||
} catch (GroupIdFormatException e) {
|
} catch (GroupIdFormatException e) {
|
||||||
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupName = ns.getString("name");
|
var groupName = ns.getString("name");
|
||||||
|
|
||||||
var groupDescription = ns.getString("description");
|
var groupDescription = ns.getString("description");
|
||||||
|
|
||||||
var groupMembers = ns.<String>getList("member");
|
var groupMembers = ns.<String>getList("member");
|
||||||
|
|
||||||
var groupRemoveMembers = ns.<String>getList("remove-member");
|
var groupRemoveMembers = ns.<String>getList("remove-member");
|
||||||
|
|
||||||
var groupAdmins = ns.<String>getList("admin");
|
var groupAdmins = ns.<String>getList("admin");
|
||||||
|
|
||||||
var groupRemoveAdmins = ns.<String>getList("remove-admin");
|
var groupRemoveAdmins = ns.<String>getList("remove-admin");
|
||||||
|
|
||||||
var groupAvatar = ns.getString("avatar");
|
var groupAvatar = ns.getString("avatar");
|
||||||
|
|
||||||
var groupResetLink = ns.getBoolean("reset-link");
|
var groupResetLink = ns.getBoolean("reset-link");
|
||||||
|
|
||||||
var groupLinkState = ns.<GroupLinkState>get("link");
|
var groupLinkState = ns.<GroupLinkState>get("link");
|
||||||
|
|
||||||
var groupExpiration = ns.getInt("expiration");
|
var groupExpiration = ns.getInt("expiration");
|
||||||
|
var groupAddMemberPermission = ns.<GroupPermission>get("set-permission-add-member");
|
||||||
|
var groupEditDetailsPermission = ns.<GroupPermission>get("set-permission-edit-details");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
|
@ -109,6 +110,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
groupRemoveAdmins,
|
groupRemoveAdmins,
|
||||||
groupResetLink,
|
groupResetLink,
|
||||||
groupLinkState != null ? groupLinkState.toLinkState() : null,
|
groupLinkState != null ? groupLinkState.toLinkState() : null,
|
||||||
|
groupAddMemberPermission != null ? groupAddMemberPermission.toManager() : null,
|
||||||
|
groupEditDetailsPermission != null ? groupEditDetailsPermission.toManager() : null,
|
||||||
groupAvatar == null ? null : new File(groupAvatar),
|
groupAvatar == null ? null : new File(groupAvatar),
|
||||||
groupExpiration);
|
groupExpiration);
|
||||||
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||||
|
@ -134,7 +137,7 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
||||||
try {
|
try {
|
||||||
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
groupId = Util.decodeGroupId(ns.getString("group")).serialize();
|
||||||
} catch (GroupIdFormatException e) {
|
} catch (GroupIdFormatException e) {
|
||||||
throw new UserErrorException("Invalid group id:" + e.getMessage());
|
throw new UserErrorException("Invalid group id: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
|
|
|
@ -349,6 +349,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
avatar == null ? null : new File(avatar),
|
avatar == null ? null : new File(avatar),
|
||||||
null);
|
null);
|
||||||
checkSendMessageResults(results.first(), results.second());
|
checkSendMessageResults(results.first(), results.second());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue