feat(communities): Update permissions list for spectated community tokens model (#11803)

Fixes: #11480

* hook up join popup to permission model

* fix chats not being put in the permission model

* make it work with channel permissions as well

---------

Co-authored-by: Jonathan Rainville <rainville.jonathan@gmail.com>
This commit is contained in:
Boris Melnik 2023-08-22 00:54:57 +06:00 committed by GitHub
parent 3e8f710560
commit 95f829665b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 281 additions and 42 deletions

View File

@ -136,3 +136,6 @@ method onUpdateViewAndPostPermissionsSatisfied*(self: AccessInterface, value: bo
method setPermissionsCheckOngoing*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getPermissionsCheckOngoing*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -410,3 +410,6 @@ method onUpdateViewAndPostPermissionsSatisfied*(self: Module, value: bool) =
method setPermissionsCheckOngoing*(self: Module, value: bool) =
self.view.setPermissionsCheckOngoing(value)
method getPermissionsCheckOngoing*(self: Module): bool =
self.view.getPermissionsCheckOngoing()

View File

@ -84,11 +84,15 @@ proc getMySectionId*(self: Controller): string =
return self.sectionId
proc asyncCheckPermissionsToJoin*(self: Controller) =
self.communityService.asyncCheckPermissionsToJoin(self.getMySectionId())
if self.delegate.getPermissionsToJoinCheckOngoing():
return
self.communityService.asyncCheckPermissionsToJoin(self.getMySectionId(), addresses = @[])
self.delegate.setPermissionsToJoinCheckOngoing(true)
proc asyncCheckAllChannelsPermissions*(self: Controller) =
self.chatService.asyncCheckAllChannelsPermissions(self.getMySectionId())
if self.delegate.getPermissionsToJoinCheckOngoing():
return
self.chatService.asyncCheckAllChannelsPermissions(self.getMySectionId(), addresses = @[])
self.delegate.setChannelsPermissionsCheckOngoing(true)
proc asyncCheckChannelPermissions*(self: Controller, communityId: string, chatId: string) =
@ -281,6 +285,11 @@ proc init*(self: Controller) =
if (args.communityId == self.sectionId):
self.delegate.onCommunityCheckPermissionsToJoinResponse(args.checkPermissionsToJoinResponse)
self.events.on(SIGNAL_CHECK_PERMISSIONS_TO_JOIN_FAILED) do(e: Args):
let args = CheckPermissionsToJoinFailedArgs(e)
if (args.communityId == self.sectionId):
self.delegate.setPermissionsToJoinCheckOngoing(false)
self.events.on(SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE) do(e: Args):
let args = CheckChannelPermissionsResponseArgs(e)
if args.communityId == self.sectionId:
@ -291,6 +300,11 @@ proc init*(self: Controller) =
if args.communityId == self.sectionId:
self.delegate.onCommunityCheckAllChannelsPermissionsResponse(args.checkAllChannelsPermissionsResponse)
self.events.on(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED) do(e: Args):
let args = CheckChannelsPermissionsErrorArgs(e)
if args.communityId == self.sectionId:
self.delegate.setPermissionsToJoinCheckOngoing(false)
self.events.on(SignalType.Wallet.event, proc(e: Args) =
var data = WalletSignal(e)
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:

View File

@ -397,5 +397,11 @@ method onCommunityCheckAllChannelsPermissionsResponse*(self: AccessInterface, ch
method setPermissionsToJoinCheckOngoing*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getPermissionsToJoinCheckOngoing*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method setChannelsPermissionsCheckOngoing*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method getChannelsPermissionsCheckOngoing*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -267,7 +267,7 @@ proc rebuildCommunityTokenPermissionsModel(self: Module) =
var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
for id, tokenPermission in community.tokenPermissions:
let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let chats = community.getCommunityChats(tokenPermission.chatIds)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
tokenPermissionsItems.add(tokenPermissionItem)
@ -769,7 +769,8 @@ method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, per
singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed")
method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let community = self.controller.getCommunityById(communityId)
let chats = community.getCommunityChats(tokenPermission.chatIds)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
self.view.tokenPermissionsModel.addItem(tokenPermissionItem)
@ -852,7 +853,8 @@ method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissions
self.setPermissionsToJoinCheckOngoing(false)
method onCommunityTokenPermissionUpdated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let community = self.controller.getCommunityById(communityId)
let chats = community.getCommunityChats(tokenPermission.chatIds)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
self.view.tokenPermissionsModel.updateItem(tokenPermission.id, tokenPermissionItem)
self.reevaluateRequiresTokenPermissionToJoin()
@ -1320,9 +1322,18 @@ method setCommunityMetrics*(self: Module, metrics: CommunityMetricsDto) =
method collectCommunityMetricsMessagesCount*(self: Module, intervals: string) =
self.controller.collectCommunityMetricsMessagesCount(intervals)
method getPermissionsToJoinCheckOngoing*(self: Module): bool =
self.view.getPermissionsCheckOngoing()
method setPermissionsToJoinCheckOngoing*(self: Module, value: bool) =
self.view.setPermissionsCheckOngoing(value)
method getChannelsPermissionsCheckOngoing*(self: Module): bool =
for chatId, cModule in self.chatContentModules:
if self.view.chatsModel().getItemPermissionsRequired(chatId):
return cModule.getPermissionsCheckOngoing()
return false
method setChannelsPermissionsCheckOngoing*(self: Module, value: bool) =
for chatId, cModule in self.chatContentModules:
if self.view.chatsModel().getItemPermissionsRequired(chatId):

View File

@ -33,6 +33,7 @@ type
tokenService: token_service.Service
chatService: chat_service.Service
tmpCommunityId: string
tmpCommunityIdForChannelsPermisisons: string
tmpAuthenticationAction: AuthenticationAction
tmpRequestToJoinEnsName: string
tmpAddressesToShare: seq[string]
@ -59,6 +60,7 @@ proc newController*(
result.tokenService = tokenService
result.chatService = chatService
result.tmpCommunityId = ""
result.tmpCommunityIdForChannelsPermisisons = ""
result.tmpRequestToJoinEnsName = ""
result.tmpAirdropAddress = ""
result.tmpAddressesToShare = @[]
@ -162,6 +164,21 @@ proc init*(self: Controller) =
let args = CommunityTokenMetadataArgs(e)
self.delegate.onCommunityTokenMetadataAdded(args.communityId, args.tokenMetadata)
self.events.on(SIGNAL_CHECK_PERMISSIONS_TO_JOIN_RESPONSE) do(e: Args):
let args = CheckPermissionsToJoinResponseArgs(e)
if (args.communityId == self.tmpCommunityId):
self.delegate.onCommunityCheckPermissionsToJoinResponse(args.communityId, args.checkPermissionsToJoinResponse)
self.tmpCommunityId = ""
self.events.on(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE) do(e: Args):
let args = CheckAllChannelsPermissionsResponseArgs(e)
if args.communityId == self.tmpCommunityIdForChannelsPermisisons:
self.delegate.onCommunityCheckAllChannelsPermissionsResponse(
args.communityId,
args.checkAllChannelsPermissionsResponse,
)
self.tmpCommunityIdForChannelsPermisisons = ""
self.events.on(SignalType.Wallet.event, proc(e: Args) =
var data = WalletSignal(e)
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:
@ -336,6 +353,7 @@ proc shareCommunityChannelUrlWithData*(self: Controller, communityId: string, ch
proc userAuthenticationCanceled*(self: Controller) =
self.tmpAuthenticationAction = AuthenticationAction.None
self.tmpCommunityId = ""
self.tmpCommunityIdForChannelsPermisisons = ""
self.tmpRequestToJoinEnsName = ""
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
@ -398,3 +416,11 @@ proc authenticateWithCallback*(self: Controller) =
proc getCommunityPublicKeyFromPrivateKey*(self: Controller, communityPrivateKey: string): string =
result = self.communityService.getCommunityPublicKeyFromPrivateKey(communityPrivateKey)
proc asyncCheckPermissionsToJoin*(self: Controller, communityId: string, addressesToShare: seq[string]) =
self.tmpCommunityId = communityId
self.communityService.asyncCheckPermissionsToJoin(communityId, addressesToShare)
proc asyncCheckAllChannelsPermissions*(self: Controller, communityId: string, sharedAddresses: seq[string]) =
self.tmpCommunityIdForChannelsPermisisons = communityId
self.chatService.asyncCheckAllChannelsPermissions(communityId, sharedAddresses)

View File

@ -1,5 +1,6 @@
import tables
import ../../../../app_service/service/community/service as community_service
import ../../../../app_service/service/chat/service as chat_service
import ../../shared_models/section_item
type
@ -206,3 +207,13 @@ method prepareTokenModelForCommunity*(self: AccessInterface, communityId: string
method getCommunityPublicKeyFromPrivateKey*(self: AccessInterface, communityPrivateKey: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method checkPermissions*(self: AccessInterface, communityId: string, sharedAddresses: seq[string]) {.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityCheckPermissionsToJoinResponse*(self: AccessInterface, communityId: string, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) {.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityCheckAllChannelsPermissionsResponse*(self: AccessInterface, communityId: string,
checkChannelPermissionsResponse: CheckAllChannelsPermissionsResponseDto) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,4 +1,4 @@
import NimQml, sequtils, tables, stint
import NimQml, sequtils, tables, stint, chronicles
import ./io_interface
import ../io_interface as delegate_interface
@ -13,7 +13,7 @@ import ./models/discord_file_list_model
import ./models/discord_import_task_item
import ./models/discord_import_tasks_model
import ../../shared_models/[member_item, section_model, section_item, token_permissions_model, token_permission_item,
token_list_item, token_list_model, token_criteria_item]
token_list_item, token_list_model, token_criteria_item, token_criteria_model, token_permission_chat_list_model]
import ../../../global/global_singleton
import ../../../core/eventemitter
import ../../../../app_service/common/types
@ -185,7 +185,7 @@ proc getCuratedCommunityItem(self: Module, community: CommunityDto): CuratedComm
var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
for id, tokenPermission in community.tokenPermissions:
let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let chats = community.getCommunityChats(tokenPermission.chatIds)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
tokenPermissionsItems.add(tokenPermissionItem)
@ -531,13 +531,75 @@ method callbackFromAuthentication*(self: Module, authenticated: bool) =
method getCommunityPublicKeyFromPrivateKey*(self: Module, communityPrivateKey: string): string =
result = self.controller.getCommunityPublicKeyFromPrivateKey(communityPrivateKey)
method checkPermissions*(self: Module, communityId: string, sharedAddresses: seq[string]) =
self.controller.asyncCheckPermissionsToJoin(communityId, sharedAddresses)
self.controller.asyncCheckAllChannelsPermissions(communityId, sharedAddresses)
method prepareTokenModelForCommunity*(self: Module, communityId: string) =
let community = self.controller.getCommunityById(communityId)
var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
for id, tokenPermission in community.tokenPermissions:
let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let chats = community.getCommunityChats(tokenPermission.chatIds)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
tokenPermissionsItems.add(tokenPermissionItem)
self.view.spectatedCommunityPermissionModel.setItems(tokenPermissionsItems)
self.view.spectatedCommunityPermissionModel.setItems(tokenPermissionsItems)
self.checkPermissions(communityId, @[])
proc applyPermissionResponse*(self: Module, communityId: string, permissions: Table[string, CheckPermissionsResultDto]) =
let community = self.controller.getCommunityById(communityId)
for id, criteriaResult in permissions:
if not community.tokenPermissions.hasKey(id):
warn "unknown permission", id
continue
let tokenPermissionItem = self.view.spectatedCommunityPermissionModel.getItemById(id)
if tokenPermissionItem.id == "":
warn "no permission in model", id
continue
var updatedTokenCriteriaItems: seq[TokenCriteriaItem] = @[]
var permissionSatisfied = true
for index, tokenCriteriaItem in tokenPermissionItem.getTokenCriteria().getItems():
let updatedTokenCriteriaItem = initTokenCriteriaItem(
tokenCriteriaItem.symbol,
tokenCriteriaItem.name,
tokenCriteriaItem.amount,
tokenCriteriaItem.`type`,
tokenCriteriaItem.ensPattern,
criteriaResult.criteria[index]
)
if criteriaResult.criteria[index] == false:
permissionSatisfied = false
updatedTokenCriteriaItems.add(updatedTokenCriteriaItem)
let updatedTokenPermissionItem = initTokenPermissionItem(
tokenPermissionItem.id,
tokenPermissionItem.`type`,
updatedTokenCriteriaItems,
tokenPermissionItem.getChatList().getItems(),
tokenPermissionItem.isPrivate,
permissionSatisfied
)
self.view.spectatedCommunityPermissionModel.updateItem(id, updatedTokenPermissionItem)
method onCommunityCheckPermissionsToJoinResponse*(self: Module, communityId: string,
checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) =
self.applyPermissionResponse(communityId, checkPermissionsToJoinResponse.permissions)
method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, communityId: string,
checkChannelPermissionsResponse: CheckAllChannelsPermissionsResponseDto) =
for _, channelPermissionResponse in checkChannelPermissionsResponse.channels:
self.applyPermissionResponse(
communityId,
channelPermissionResponse.viewOnlyPermissions.permissions,
)
self.applyPermissionResponse(
communityId,
channelPermissionResponse.viewAndPostPermissions.permissions,
)

View File

@ -314,6 +314,13 @@ QtObject:
proc prepareTokenModelForCommunity(self: View, communityId: string) {.slot.} =
self.delegate.prepareTokenModelForCommunity(communityId)
proc checkPermissions*(self: View, communityId: string, addressesToShare: string) {.slot.} =
try:
let sharedAddresses = map(parseJson(addressesToShare).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.checkPermissions(communityId, sharedAddresses)
except Exception as e:
echo "Error updating token model with addresses: ", e.msg
proc getSpectatedCommunityPermissionModel(self: View): QVariant {.slot.} =
return self.spectatedCommunityPermissionModelVariant

View File

@ -39,11 +39,12 @@ const asyncCheckChannelPermissionsTask: Task = proc(argEncoded: string) {.gcsafe
type
AsyncCheckAllChannelsPermissionsTaskArg = ref object of QObjectTaskArg
communityId: string
addresses: seq[string]
const asyncCheckAllChannelsPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckAllChannelsPermissionsTaskArg](argEncoded)
try:
let response = status_communities.checkAllCommunityChannelsPermissions(arg.communityId)
let response = status_communities.checkAllCommunityChannelsPermissions(arg.communityId, arg.addresses)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,

View File

@ -97,6 +97,9 @@ type
communityId*: string
checkAllChannelsPermissionsResponse*: CheckAllChannelsPermissionsResponseDto
CheckChannelsPermissionsErrorArgs* = ref object of Args
communityId*: string
error*: string
# Signals which may be emitted by this service:
const SIGNAL_CHANNEL_GROUPS_LOADED* = "channelGroupsLoaded"
@ -121,6 +124,7 @@ const SIGNAL_CHAT_CREATED* = "chatCreated"
const SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND* = "chatRequestUpdateAfterSend"
const SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE* = "checkChannelPermissionsResponse"
const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE* = "checkAllChannelsPermissionsResponse"
const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED* = "checkAllChannelsPermissionsFailed"
QtObject:
type Service* = ref object of QObject
@ -424,7 +428,9 @@ QtObject:
return self.chats[chatId]
proc getChatsByIds*(self: Service, chatIds: seq[string]): seq[ChatDto] =
proc getChatsByIds*(self: Service, chatIds: seq[string]): seq[ChatDto] =
if chatIds.len == 0:
return
return self.getAllChats().filterIt(it.id in chatIds)
proc getOneToOneChatNameAndImage*(self: Service, chatId: string):
@ -786,28 +792,34 @@ QtObject:
let errMsg = e.msg
error "error checking all channel permissions: ", errMsg
proc asyncCheckAllChannelsPermissions*(self: Service, communityId: string) =
proc asyncCheckAllChannelsPermissions*(self: Service, communityId: string, addresses: seq[string]) =
let arg = AsyncCheckAllChannelsPermissionsTaskArg(
tptr: cast[ByteAddress](asyncCheckAllChannelsPermissionsTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckAllChannelsPermissionsDone",
communityId: communityId
communityId: communityId,
addresses: addresses,
)
self.threadpool.start(arg)
proc onAsyncCheckAllChannelsPermissionsDone*(self: Service, rpcResponse: string) {.slot.} =
let rpcResponseObj = rpcResponse.parseJson
let communityId = rpcResponseObj{"communityId"}.getStr()
try:
let rpcResponseObj = rpcResponse.parseJson
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error checking all community channel permissions", msg = error.message
return
raise newException(CatchableError, rpcResponseObj["error"].getStr)
if rpcResponseObj["response"]{"error"}.kind != JNull:
let error = Json.decode(rpcResponseObj["response"]["error"].getStr, RpcError)
raise newException(RpcException, error.message)
let communityId = rpcResponseObj{"communityId"}.getStr()
let checkAllChannelsPermissionsResponse = rpcResponseObj["response"]["result"].toCheckAllChannelsPermissionsResponseDto()
self.channelGroups[communityId].channelPermissions = checkAllChannelsPermissionsResponse
self.events.emit(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE, CheckAllChannelsPermissionsResponseArgs(communityId: communityId, checkAllChannelsPermissionsResponse: checkAllChannelsPermissionsResponse))
except Exception as e:
let errMsg = e.msg
error "error checking all channels permissions: ", errMsg
self.events.emit(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED, CheckChannelsPermissionsErrorArgs(
communityId: communityId,
error: errMsg,
))

View File

@ -153,11 +153,12 @@ const asyncEditSharedAddressesTask: Task = proc(argEncoded: string) {.gcsafe, ni
type
AsyncCheckPermissionsToJoinTaskArg = ref object of QObjectTaskArg
communityId: string
addresses: seq[string]
const asyncCheckPermissionsToJoinTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckPermissionsToJoinTaskArg](argEncoded)
try:
let response = status_go.checkPermissionsToJoinCommunity(arg.communityId)
let response = status_go.checkPermissionsToJoinCommunity(arg.communityId, arg.addresses)
arg.finish(%* {
"response": response,
"communityId": arg.communityId,

View File

@ -553,4 +553,13 @@ proc toRevealedAccounts*(revealedAccountsObj: JsonNode): seq[RevealedAccount] =
proc toMembersRevealedAccounts*(membersRevealedAccountsObj: JsonNode): MembersRevealedAccounts =
result = initTable[string, seq[RevealedAccount]]()
for (pubkey, revealedAccountsObj) in membersRevealedAccountsObj.pairs:
result[pubkey] = revealedAccountsObj.toRevealedAccounts()
result[pubkey] = revealedAccountsObj.toRevealedAccounts()
proc getCommunityChats*(self: CommunityDto, chatsIds: seq[string]): seq[ChatDto] =
var chats: seq[ChatDto] = @[]
for chatId in chatsIds:
for communityChat in self.chats:
if chatId == communityChat.id:
chats.add(communityChat)
break
return chats

View File

@ -121,6 +121,10 @@ type
communityId*: string
checkPermissionsToJoinResponse*: CheckPermissionsToJoinResponseDto
CheckPermissionsToJoinFailedArgs* = ref object of Args
communityId*: string
error*: string
CommunityMetricsArgs* = ref object of Args
communityId*: string
metricsType*: CommunityMetricsType
@ -195,6 +199,7 @@ const TOKEN_PERMISSIONS_ADDED = "tokenPermissionsAdded"
const TOKEN_PERMISSIONS_MODIFIED = "tokenPermissionsModified"
const SIGNAL_CHECK_PERMISSIONS_TO_JOIN_RESPONSE* = "checkPermissionsToJoinResponse"
const SIGNAL_CHECK_PERMISSIONS_TO_JOIN_FAILED* = "checkPermissionsToJoinFailed"
const SIGNAL_COMMUNITY_PRIVATE_KEY_REMOVED* = "communityPrivateKeyRemoved"
@ -1412,29 +1417,40 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community))
proc asyncCheckPermissionsToJoin*(self: Service, communityId: string) =
proc asyncCheckPermissionsToJoin*(self: Service, communityId: string, addresses: seq[string]) =
let arg = AsyncCheckPermissionsToJoinTaskArg(
tptr: cast[ByteAddress](asyncCheckPermissionsToJoinTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckPermissionsToJoinDone",
communityId: communityId
communityId: communityId,
addresses: addresses
)
self.threadpool.start(arg)
proc onAsyncCheckPermissionsToJoinDone*(self: Service, rpcResponse: string) {.slot.} =
let rpcResponseObj = rpcResponse.parseJson
let communityId = rpcResponseObj{"communityId"}.getStr()
try:
let rpcResponseObj = rpcResponse.parseJson
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error checking permissions to join", msg = error.message
return
raise newException(CatchableError, rpcResponseObj["error"].getStr)
if rpcResponseObj["response"]{"error"}.kind != JNull:
let error = Json.decode(rpcResponseObj["response"]["error"].getStr, RpcError)
raise newException(RpcException, error.message)
let communityId = rpcResponseObj{"communityId"}.getStr()
let checkPermissionsToJoinResponse = rpcResponseObj["response"]["result"].toCheckPermissionsToJoinResponseDto
self.events.emit(SIGNAL_CHECK_PERMISSIONS_TO_JOIN_RESPONSE, CheckPermissionsToJoinResponseArgs(communityId: communityId, checkPermissionsToJoinResponse: checkPermissionsToJoinResponse))
self.events.emit(SIGNAL_CHECK_PERMISSIONS_TO_JOIN_RESPONSE, CheckPermissionsToJoinResponseArgs(
communityId: communityId,
checkPermissionsToJoinResponse: checkPermissionsToJoinResponse
))
except Exception as e:
let errMsg = e.msg
error "error checking permissions to join: ", errMsg
error "Error checking permissions to join: ", errMsg
self.events.emit(SIGNAL_CHECK_PERMISSIONS_TO_JOIN_FAILED, CheckPermissionsToJoinFailedArgs(
communityId: communityId,
error: errMsg,
))
proc asyncRequestToJoinCommunity*(self: Service, communityId: string, ensName: string, password: string,
addressesToShare: seq[string], airdropAddress: string) =

View File

@ -72,9 +72,10 @@ proc getRevealedAccountsForAllMembers*(
): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("getRevealedAccountsForAllMembers".prefix, %*[communityId])
proc checkPermissionsToJoinCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
proc checkPermissionsToJoinCommunity*(communityId: string, addresses: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("checkPermissionsToJoinCommunity".prefix, %*[{
"communityId": communityId
"communityId": communityId,
"addresses": addresses
}])
proc checkCommunityChannelPermissions*(communityId: string, chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
@ -83,9 +84,10 @@ proc checkCommunityChannelPermissions*(communityId: string, chatId: string): Rpc
"chatId": chatId
}])
proc checkAllCommunityChannelsPermissions*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
proc checkAllCommunityChannelsPermissions*(communityId: string, addresses: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("checkAllCommunityChannelsPermissions".prefix, %*[{
"communityId": communityId
"communityId": communityId,
"addresses": addresses,
}])
proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =

View File

@ -184,7 +184,10 @@ StackLayout {
loginType: root.rootStore.loginType
walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
permissionsModel: root.permissionsStore.permissionsModel
permissionsModel: {
root.rootStore.prepareTokenModelForCommunity(communityIntroDialog.communityId)
return root.rootStore.permissionsModel
}
assetsModel: root.rootStore.assetsModel
collectiblesModel: root.rootStore.collectiblesModel
@ -197,6 +200,10 @@ StackLayout {
mainViewLoader.item.isInvitationPending = root.rootStore.isCommunityRequestPending(communityIntroDialog.communityId)
}
onSharedAddressesUpdated: {
root.rootStore.updatePermissionsModel(communityIntroDialog.communityId, sharedAddresses)
}
onClosed: {
destroy()
}

View File

@ -56,6 +56,13 @@ QtObject {
}
}
function prepareTokenModelForCommunity(publicKey) {
root.communitiesModuleInst.prepareTokenModelForCommunity(publicKey)
}
readonly property var permissionsModel: !!root.communitiesModuleInst.spectatedCommunityPermissionModel ?
root.communitiesModuleInst.spectatedCommunityPermissionModel : null
readonly property string overviewChartData: chatCommunitySectionModule.overviewChartData
readonly property bool isUserAllowedToSendMessage: _d.isUserAllowedToSendMessage
@ -782,4 +789,8 @@ QtObject {
restoreMode: Binding.RestoreBindingOrValue
}
}
function updatePermissionsModel(communityId, sharedAddresses) {
communitiesModuleInst.checkPermissions(communityId, JSON.stringify(sharedAddresses))
}
}

View File

@ -74,6 +74,7 @@ Control {
property var selectedSharedAddresses: []
property string selectedAirdropAddress
signal sharedAddressesChanged(string airdropAddress, var sharedAddresses)
signal shareSelectedAddressesClicked(string airdropAddress, var sharedAddresses)
signal saveSelectedAddressesClicked(string airdropAddress, var sharedAddresses)
@ -169,6 +170,7 @@ Control {
onAddressesChanged: {
root.selectedSharedAddresses = selectedSharedAddresses
root.selectedAirdropAddress = selectedAirdropAddress
root.sharedAddressesChanged(selectedAirdropAddress, selectedSharedAddresses)
}
}

View File

@ -25,6 +25,7 @@ StatusDialog {
signal shareSelectedAddressesClicked(string airdropAddress, var sharedAddresses)
signal saveSelectedAddressesClicked(string airdropAddress, var sharedAddresses)
signal sharedAddressesChanged(string airdropAddress, var sharedAddresses)
title: panel.title
implicitWidth: 640 // by design
@ -42,6 +43,9 @@ StatusDialog {
collectiblesModel: root.collectiblesModel
onShareSelectedAddressesClicked: root.shareSelectedAddressesClicked(airdropAddress, sharedAddresses)
onSaveSelectedAddressesClicked: root.saveSelectedAddressesClicked(airdropAddress, sharedAddresses)
onSharedAddressesChanged: {
root.sharedAddressesChanged(airdropAddress, sharedAddresses)
}
onClose: root.close()
}

View File

@ -125,7 +125,10 @@ Item {
accessType: communityData.access
loginType: root.store.loginType
walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
permissionsModel: root.store.permissionsStore.permissionsModel
permissionsModel: {
root.store.prepareTokenModelForCommunity(communityData.id)
return root.store.permissionsModel
}
assetsModel: root.store.assetsModel
collectiblesModel: root.store.collectiblesModel
@ -137,6 +140,10 @@ Item {
root.store.cancelPendingRequest(communityData.id)
joinCommunityButton.invitationPending = root.store.isCommunityRequestPending(communityData.id)
}
onSharedAddressesUpdated: {
root.store.updatePermissionsModel(communityData.id, sharedAddresses)
}
onClosed: destroy()
}
}

View File

@ -234,13 +234,20 @@ SettingsContentBase {
loginType: chatStore.loginType
walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
permissionsModel: chatStore.permissionsStore.permissionsModel
permissionsModel: {
root.rootStore.prepareTokenModelForCommunity(communityIntroDialog.communityId)
return root.rootStore.permissionsModel
}
assetsModel: chatStore.assetsModel
collectiblesModel: chatStore.collectiblesModel
onJoined: chatStore.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, root.rootStore.userProfileInst.name, JSON.stringify(sharedAddresses), airdropAddress)
onCancelMembershipRequest: root.rootStore.cancelPendingRequest(communityIntroDialog.communityId)
onSharedAddressesUpdated: {
root.rootStore.updatePermissionsModel(communityIntroDialog.communityId, sharedAddresses)
}
onClosed: destroy()
}
}

View File

@ -39,7 +39,7 @@ QtObject {
root.prepareTokenModelForCommunity(communityKeyToImport);
}
property var permissionsModel: !!root.communitiesModuleInst.spectatedCommunityPermissionModel ?
readonly property var permissionsModel: !!root.communitiesModuleInst.spectatedCommunityPermissionModel ?
root.communitiesModuleInst.spectatedCommunityPermissionModel : null
property var walletAccountsModel: WalletStore.RootStore.watchOnlyAccounts
property var assetsModel: SortFilterProxyModel {
@ -236,4 +236,8 @@ QtObject {
function requestToJoinCommunityWithAuthentication(communityId, ensName, addressesToShare = [], airdropAddress = "") {
communitiesModuleInst.requestToJoinCommunityWithAuthenticationWithSharedAddresses(communityId, ensName, JSON.stringify(addressesToShare), airdropAddress)
}
function updatePermissionsModel(communityId, sharedAddresses) {
communitiesModuleInst.checkPermissions(communityId, JSON.stringify(sharedAddresses))
}
}

View File

@ -524,7 +524,10 @@ QtObject {
property string communityId
loginType: root.rootStore.loginType
walletAccountsModel: root.rootStore.walletAccountsModel
permissionsModel: root.rootStore.permissionsModel
permissionsModel: {
root.rootStore.prepareTokenModelForCommunity(communityIntroDialog.communityId)
return root.rootStore.permissionsModel
}
assetsModel: root.rootStore.assetsModel
collectiblesModel: root.rootStore.collectiblesModel
onJoined: root.rootStore.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, communityIntroDialog.name, JSON.stringify(sharedAddresses), airdropAddress)
@ -546,6 +549,9 @@ QtObject {
communityIntroDialog.close();
}
}
onSharedAddressesUpdated: {
root.rootStore.updatePermissionsModel(communityIntroDialog.communityId, sharedAddresses)
}
onAboutToShow: { root.rootStore.communityKeyToImport = communityIntroDialog.communityId; }
onClosed: { root.rootStore.communityKeyToImport = ""; destroy(); }
}
@ -707,7 +713,10 @@ QtObject {
//selectedAirdropAddress: "???"
loginType: chatStore.loginType
walletAccountsModel: WalletStore.RootStore.receiveAccounts
permissionsModel: chatStore.permissionsStore.permissionsModel
permissionsModel: {
root.rootStore.prepareTokenModelForCommunity(editSharedAddressesPopup.communityId)
return root.rootStore.permissionsModel
}
assetsModel: chatStore.assetsModel
collectiblesModel: chatStore.collectiblesModel

View File

@ -32,6 +32,7 @@ StatusStackModal {
signal joined(string airdropAddress, var sharedAddresses)
signal cancelMembershipRequest()
signal sharedAddressesUpdated(var sharedAddresses)
width: 640 // by design
padding: 0
@ -129,6 +130,9 @@ StatusStackModal {
d.selectedSharedAddresses = sharedAddresses
root.replaceItem = undefined // go back, unload us
}
onSharedAddressesChanged: {
root.sharedAddressesUpdated(sharedAddresses)
}
}
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 59af87b82f4bdeee2d4c550167a28552db53d3c8
Subproject commit 3bf0bed78da660b0a361afd285ec229dcef7de70