Skip to content

Commit ae93eec

Browse files
authored
Fix/control panel button issue (#309)
* fix: button * chore: fix control panel storage selection * chore: fix control panel evault selection
1 parent 018d62d commit ae93eec

File tree

6 files changed

+112
-14
lines changed

6 files changed

+112
-14
lines changed

infrastructure/control-panel/src/routes/monitoring/+page.svelte

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,20 @@
3737
3838
if (evaultsData) {
3939
selectedEVaults = JSON.parse(evaultsData);
40+
console.log('Loaded selectedEVaults from sessionStorage:', selectedEVaults);
4041
}
4142
if (platformsData) {
4243
selectedPlatforms = JSON.parse(platformsData);
44+
console.log('Loaded selectedPlatforms from sessionStorage:', selectedPlatforms);
45+
}
46+
47+
// Check if any items are selected, if not show selection interface
48+
if (
49+
(!selectedEVaults || selectedEVaults.length === 0) &&
50+
(!selectedPlatforms || selectedPlatforms.length === 0)
51+
) {
52+
// Don't redirect, just show empty state
53+
return;
4354
}
4455
4556
// Check if any items are selected, if not show selection interface
@@ -176,6 +187,8 @@
176187
}
177188
178189
function handleFlowEvent(data: any) {
190+
console.log('handleFlowEvent received:', data);
191+
179192
switch (data.type) {
180193
case 'evault_sync_event':
181194
handleEvaultSyncEvent(data);
@@ -196,10 +209,21 @@
196209
}
197210
198211
function handleEvaultSyncEvent(data: any) {
212+
console.log('handleEvaultSyncEvent received data:', data);
213+
console.log('selectedEVaults:', selectedEVaults);
214+
console.log('selectedPlatforms:', selectedPlatforms);
215+
199216
// Map the real data to visualization indices
200217
const platformIndex = getPlatformIndex(data.platform);
201218
const evaultIndex = getEvaultIndex(data.w3id);
202219
220+
console.log('Mapped indices:', {
221+
platformIndex,
222+
evaultIndex,
223+
platform: data.platform,
224+
w3id: data.w3id
225+
});
226+
203227
// Step 1: Platform creates entry locally
204228
currentFlowStep = 1;
205229
flowMessages = [
@@ -477,8 +501,40 @@
477501
}
478502
479503
function getEvaultIndex(w3id: string): number {
480-
const index = selectedEVaults.findIndex((e) => e.evaultId === w3id || e.w3id === w3id);
481-
return index >= 0 ? index : 0;
504+
console.log('getEvaultIndex called with w3id:', w3id);
505+
console.log('selectedEVaults:', selectedEVaults);
506+
507+
// Since evaultId is the same as w3id, prioritize that match
508+
const index = selectedEVaults.findIndex((e) => {
509+
const matches = e.evaultId === w3id;
510+
511+
if (matches) {
512+
console.log('Found matching eVault by evaultId:', e);
513+
}
514+
515+
return matches;
516+
});
517+
518+
console.log('getEvaultIndex result:', {
519+
w3id,
520+
foundIndex: index,
521+
selectedEVaultsLength: selectedEVaults.length
522+
});
523+
524+
// If no match found, log all available evaultIds for debugging
525+
if (index === -1) {
526+
console.log('No match found for w3id:', w3id);
527+
console.log('Available evaultIds:');
528+
selectedEVaults.forEach((evault, i) => {
529+
console.log(`eVault ${i}: evaultId = "${evault.evaultId}"`);
530+
});
531+
532+
// Fall back to index 0 if no match found
533+
console.log('Falling back to index 0');
534+
return 0;
535+
}
536+
537+
return index;
482538
}
483539
</script>
484540

infrastructure/eid-wallet/src-tauri/gen/apple/eid-wallet.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@
388388
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
389389
CODE_SIGN_ENTITLEMENTS = "eid-wallet_iOS/eid-wallet_iOS.entitlements";
390390
CODE_SIGN_IDENTITY = "iPhone Developer";
391-
CURRENT_PROJECT_VERSION = 0.2.0.1;
391+
CURRENT_PROJECT_VERSION = 0.2.0.2;
392392
DEVELOPMENT_TEAM = M49C8XS835;
393393
ENABLE_BITCODE = NO;
394394
"EXCLUDED_ARCHS[sdk=iphoneos*]" = x86_64;
@@ -416,7 +416,7 @@
416416
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
417417
);
418418
MARKETING_VERSION = 0.2.0;
419-
PRODUCT_BUNDLE_IDENTIFIER = foundation.metastate.eid-wallet;
419+
PRODUCT_BUNDLE_IDENTIFIER = "foundation.metastate.eid-wallet";
420420
PRODUCT_NAME = "eID for W3DS";
421421
SDKROOT = iphoneos;
422422
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -436,7 +436,7 @@
436436
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
437437
CODE_SIGN_ENTITLEMENTS = "eid-wallet_iOS/eid-wallet_iOS.entitlements";
438438
CODE_SIGN_IDENTITY = "iPhone Developer";
439-
CURRENT_PROJECT_VERSION = 0.2.0.1;
439+
CURRENT_PROJECT_VERSION = 0.2.0.2;
440440
DEVELOPMENT_TEAM = M49C8XS835;
441441
ENABLE_BITCODE = NO;
442442
"EXCLUDED_ARCHS[sdk=iphoneos*]" = x86_64;
@@ -464,7 +464,7 @@
464464
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
465465
);
466466
MARKETING_VERSION = 0.2.0;
467-
PRODUCT_BUNDLE_IDENTIFIER = foundation.metastate.eid-wallet;
467+
PRODUCT_BUNDLE_IDENTIFIER = "foundation.metastate.eid-wallet";
468468
PRODUCT_NAME = "eID for W3DS";
469469
SDKROOT = iphoneos;
470470
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

infrastructure/eid-wallet/src-tauri/gen/apple/eid-wallet_iOS/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</dict>
2929
</array>
3030
<key>CFBundleVersion</key>
31-
<string>0.2.0.1</string>
31+
<string>0.2.0.2</string>
3232
<key>LSRequiresIPhoneOS</key>
3333
<true/>
3434
<key>NSAppTransportSecurity</key>
@@ -61,4 +61,4 @@
6161
<string>UIInterfaceOrientationLandscapeRight</string>
6262
</array>
6363
</dict>
64-
</plist>
64+
</plist>

platforms/evoting-api/src/controllers/PollController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class PollController {
2323
});
2424
}
2525

26-
const result = await this.pollService.getAllPolls(page, limit, search, sortField, sortDirection);
26+
const userId = (req as any).user.id;
27+
const result = await this.pollService.getAllPolls(page, limit, search, sortField, sortDirection, userId);
2728
res.json(result);
2829
} catch (error) {
2930
console.error("Error fetching polls:", error);

platforms/evoting-api/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ app.post("/api/groups/:id/admins", authGuard, groupController.addAdmins);
193193
app.delete("/api/groups/:id/admins/:userId", authGuard, groupController.removeAdmin);
194194

195195
// Poll routes
196-
app.get("/api/polls", pollController.getAllPolls);
196+
app.get("/api/polls", authGuard, pollController.getAllPolls);
197197
app.get("/api/polls/my", authGuard, pollController.getPollsByCreator);
198198
app.post("/api/polls", authGuard, pollController.createPoll);
199199
app.put("/api/polls/:id", authGuard, pollController.updatePoll);

platforms/evoting-api/src/services/PollService.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Repository } from "typeorm";
22
import { AppDataSource } from "../database/data-source";
33
import { Poll } from "../database/entities/Poll";
44
import { User } from "../database/entities/User";
5+
import { Group } from "../database/entities/Group";
56
import { MessageService } from "./MessageService";
67

78
export class PollService {
@@ -15,7 +16,7 @@ export class PollService {
1516
this.messageService = new MessageService();
1617
}
1718

18-
async getAllPolls(page: number = 1, limit: number = 15, search?: string, sortField: string = "deadline", sortDirection: "asc" | "desc" = "asc"): Promise<{ polls: Poll[]; total: number; page: number; limit: number; totalPages: number }> {
19+
async getAllPolls(page: number = 1, limit: number = 15, search?: string, sortField: string = "deadline", sortDirection: "asc" | "desc" = "asc", userId?: string): Promise<{ polls: Poll[]; total: number; page: number; limit: number; totalPages: number }> {
1920
// First, get all polls that match the search criteria (without pagination)
2021
let whereClause: any = {};
2122
if (search) {
@@ -25,6 +26,29 @@ export class PollService {
2526
];
2627
}
2728

29+
// Get user's group memberships if userId is provided
30+
let userGroupIds: string[] = [];
31+
if (userId) {
32+
const user = await this.userRepository.findOne({
33+
where: { id: userId },
34+
relations: ['followers', 'following'] // This will include group memberships
35+
});
36+
37+
if (user) {
38+
// Get groups where user is a member, admin, or participant
39+
const groupRepository = AppDataSource.getRepository(Group);
40+
const userGroups = await groupRepository
41+
.createQueryBuilder('group')
42+
.leftJoin('group.members', 'member')
43+
.leftJoin('group.admins', 'admin')
44+
.leftJoin('group.participants', 'participant')
45+
.where('member.id = :userId OR admin.id = :userId OR participant.id = :userId', { userId })
46+
.getMany();
47+
48+
userGroupIds = userGroups.map(group => group.id);
49+
}
50+
}
51+
2852
const [allPolls, total] = await this.pollRepository.findAndCount({
2953
where: whereClause,
3054
relations: ["creator"],
@@ -33,8 +57,25 @@ export class PollService {
3357
}
3458
});
3559

60+
// Filter polls based on user's group memberships
61+
let filteredPolls = allPolls;
62+
if (userId && userGroupIds.length > 0) {
63+
filteredPolls = allPolls.filter(poll => {
64+
// Show polls that:
65+
// 1. Have no groupId (public polls)
66+
// 2. Belong to groups where user is a member/admin/participant
67+
// 3. Are created by the user themselves
68+
return !poll.groupId ||
69+
userGroupIds.includes(poll.groupId) ||
70+
poll.creatorId === userId;
71+
});
72+
} else if (userId) {
73+
// If user has no group memberships, only show their own polls and public polls
74+
filteredPolls = allPolls.filter(poll => !poll.groupId || poll.creatorId === userId);
75+
}
76+
3677
// Custom sorting based on sortField and sortDirection
37-
const sortedPolls = allPolls.sort((a, b) => {
78+
const sortedPolls = filteredPolls.sort((a, b) => {
3879
const now = new Date();
3980
const aIsActive = !a.deadline || new Date(a.deadline) > now;
4081
const bIsActive = !b.deadline || new Date(b.deadline) > now;
@@ -86,11 +127,11 @@ export class PollService {
86127
const skip = (page - 1) * limit;
87128
const paginatedPolls = sortedPolls.slice(skip, skip + limit);
88129

89-
const totalPages = Math.ceil(total / limit);
130+
const totalPages = Math.ceil(filteredPolls.length / limit);
90131

91132
return {
92133
polls: paginatedPolls,
93-
total,
134+
total: filteredPolls.length,
94135
page,
95136
limit,
96137
totalPages

0 commit comments

Comments
 (0)