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.GroupLinkState;
|
||||
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.NotAGroupMemberException;
|
||||
import org.asamk.signal.manager.helper.GroupV2Helper;
|
||||
|
@ -836,6 +837,8 @@ public class Manager implements Closeable {
|
|||
List<String> removeAdmins,
|
||||
boolean resetGroupLink,
|
||||
GroupLinkState groupLinkState,
|
||||
GroupPermission addMemberPermission,
|
||||
GroupPermission editDetailsPermission,
|
||||
File avatarFile,
|
||||
Integer expirationTimer
|
||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||
|
@ -848,6 +851,8 @@ public class Manager implements Closeable {
|
|||
removeAdmins == null ? null : getSignalServiceAddresses(removeAdmins),
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
addMemberPermission,
|
||||
editDetailsPermission,
|
||||
avatarFile,
|
||||
expirationTimer);
|
||||
}
|
||||
|
@ -862,8 +867,10 @@ public class Manager implements Closeable {
|
|||
final Set<RecipientId> removeAdmins,
|
||||
final boolean resetGroupLink,
|
||||
final GroupLinkState groupLinkState,
|
||||
final GroupPermission addMemberPermission,
|
||||
final GroupPermission editDetailsPermission,
|
||||
final File avatarFile,
|
||||
Integer expirationTimer
|
||||
final Integer expirationTimer
|
||||
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||
var group = getGroupForUpdating(groupId);
|
||||
|
||||
|
@ -877,6 +884,8 @@ public class Manager implements Closeable {
|
|||
removeAdmins,
|
||||
resetGroupLink,
|
||||
groupLinkState,
|
||||
addMemberPermission,
|
||||
editDetailsPermission,
|
||||
avatarFile,
|
||||
expirationTimer);
|
||||
}
|
||||
|
@ -948,6 +957,8 @@ public class Manager implements Closeable {
|
|||
final Set<RecipientId> removeAdmins,
|
||||
final boolean resetGroupLink,
|
||||
final GroupLinkState groupLinkState,
|
||||
final GroupPermission addMemberPermission,
|
||||
final GroupPermission editDetailsPermission,
|
||||
final File avatarFile,
|
||||
Integer expirationTimer
|
||||
) throws IOException {
|
||||
|
@ -1020,6 +1031,16 @@ public class Manager implements Closeable {
|
|||
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) {
|
||||
var groupGroupChangePair = groupV2Helper.setMessageExpirationTimer(group, expirationTimer);
|
||||
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.GroupLinkState;
|
||||
import org.asamk.signal.manager.groups.GroupPermission;
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfoV2;
|
||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||
|
@ -314,6 +315,26 @@ public class GroupV2Helper {
|
|||
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(
|
||||
GroupMasterKey groupMasterKey,
|
||||
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) {
|
||||
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
|
||||
import org.asamk.Signal;
|
||||
import org.asamk.signal.GroupLinkState;
|
||||
import org.asamk.signal.GroupPermission;
|
||||
import org.asamk.signal.PlainTextWriterImpl;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
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")
|
||||
.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)");
|
||||
}
|
||||
|
||||
|
@ -72,24 +80,17 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
}
|
||||
|
||||
var groupName = ns.getString("name");
|
||||
|
||||
var groupDescription = ns.getString("description");
|
||||
|
||||
var groupMembers = ns.<String>getList("member");
|
||||
|
||||
var groupRemoveMembers = ns.<String>getList("remove-member");
|
||||
|
||||
var groupAdmins = ns.<String>getList("admin");
|
||||
|
||||
var groupRemoveAdmins = ns.<String>getList("remove-admin");
|
||||
|
||||
var groupAvatar = ns.getString("avatar");
|
||||
|
||||
var groupResetLink = ns.getBoolean("reset-link");
|
||||
|
||||
var groupLinkState = ns.<GroupLinkState>get("link");
|
||||
|
||||
var groupExpiration = ns.getInt("expiration");
|
||||
var groupAddMemberPermission = ns.<GroupPermission>get("set-permission-add-member");
|
||||
var groupEditDetailsPermission = ns.<GroupPermission>get("set-permission-edit-details");
|
||||
|
||||
try {
|
||||
if (groupId == null) {
|
||||
|
@ -109,6 +110,8 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
|
|||
groupRemoveAdmins,
|
||||
groupResetLink,
|
||||
groupLinkState != null ? groupLinkState.toLinkState() : null,
|
||||
groupAddMemberPermission != null ? groupAddMemberPermission.toManager() : null,
|
||||
groupEditDetailsPermission != null ? groupEditDetailsPermission.toManager() : null,
|
||||
groupAvatar == null ? null : new File(groupAvatar),
|
||||
groupExpiration);
|
||||
ErrorUtils.handleTimestampAndSendMessageResults(writer, results.first(), results.second());
|
||||
|
|
|
@ -349,6 +349,8 @@ public class DbusSignalImpl implements Signal {
|
|||
null,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
avatar == null ? null : new File(avatar),
|
||||
null);
|
||||
checkSendMessageResults(results.first(), results.second());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue