Merge branch 'module/poll' into dev
All checks were successful
Build Docker Image / Docker-Build (push) Successful in 2m18s
Build Docker Image / Clean-Registry (push) Successful in -6s

This commit is contained in:
2026-03-10 09:36:48 +01:00
6 changed files with 54 additions and 4 deletions

View File

@@ -111,7 +111,7 @@ public class Poll implements Mappable {
private HashMap<Integer,Map<Integer,Integer>> selections = new HashMap<>();
public void count(ResultSet rs) throws SQLException {
var optionId = rs.getInt(OPTION_ID);
var userId = rs.getObject(USER_ID);
var userId = rs.getObject(USER);
var weight = rs.getInt(WEIGHT);
var optionStats = selections.computeIfAbsent(optionId, k -> new HashMap<>());
optionStats.compute(weight, (k, sum) -> sum == null ? 1 : sum + 1);

View File

@@ -72,7 +72,7 @@
</td>
<td class="histogram">
{#each Object.entries(hist).sort((a,b) => a[0] - b[0]) as [weight,count]}
<span style="height: {100*count/max_val(hist)}%">
<span style="height: {100*count/max_val(hist)}%" title={t('voted {count} times',{count:count})}>
<span>{weight}</span>
</span>
{/each}

View File

@@ -96,7 +96,6 @@ public class PollModule extends BaseHandler implements PollService {
var poll = pollDb.loadPoll(pollId);
var permitted = !poll.isPrivate() || poll.owner().equals(user);
if (!permitted && poll.permissions().get(user) == null) throw forbidden(Text.NOT_ALLOWED_TO_EDIT, Field.OBJECT,Text.POLL);
var eval = pollDb.loadEvaluation(pollId);
return sendContent(ex,poll);
}

View File

@@ -9,9 +9,11 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.constants.Field.DESCRIPTION;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.core.model.Permission.READ_ONLY;
import static de.srsoftware.umbrella.poll.Constants.*;
import static java.text.MessageFormat.format;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.constants.Text;
@@ -40,8 +42,10 @@ public class SqliteDb extends BaseDb implements PollDb {
createSelectionsTable();
case 1:
createSharesTable();
case 2:
updateSharesTable();
}
return setCurrentVersion(2);
return setCurrentVersion(3);
}
private void createOptionsTable() {
@@ -295,4 +299,49 @@ public class SqliteDb extends BaseDb implements PollDb {
return option;
}
private void updateSharesTable() {
try {
var newPermissions = new HashMap<String, Map<Long, Permission>>(); // Map from PollId → (Map from UserId → Permission)
var rs = select(ALL).from(TABLE_SHARES).exec(db);
while (rs.next()) {
var pollID = rs.getString(POLL_ID);
var userId = rs.getLong(USER_ID);
var perm = rs.getInt(PERMISSION);
var userMap = newPermissions.computeIfAbsent(pollID, k -> new HashMap<>());
switch (perm) {
case 0:
userMap.put(userId, READ_ONLY);
break;
case 1:
case 2:
userMap.put(userId, Permission.EDIT);
break;
default:
userMap.put(userId, null);
}
}
rs.close();
for (var pollEntry : newPermissions.entrySet()){
var pollId = pollEntry.getKey();
for (var userEntry : pollEntry.getValue().entrySet()){
var userId = userEntry.getKey();
var permission = userEntry.getValue();
if (permission == null) {
Query.delete().from(TABLE_SHARES)
.where(USER_ID, equal(userId))
.where(POLL_ID, equal(pollId))
.execute(db);
} else {
Query.update(TABLE_SHARES)
.where(USER_ID, equal(userId))
.where(POLL_ID, equal(pollId))
.set(PERMISSION).prepare(db)
.apply(permission.code()).close();
}
}
}
} catch (SQLException ex){
throw databaseException("Failed to update permissions in shares table!");
}
}
}

View File

@@ -418,6 +418,7 @@
"version": "Version",
"version_of": "Version {version} von {element}",
"visible_to_guests": "Für Besucher sichtbar",
"voted {count} times": "{count} mal gewählt",
"website": "Website",
"welcome" : "Willkommen, {0}",

View File

@@ -418,6 +418,7 @@
"version": "version",
"version_of": "version {version} of {element}",
"visible_to_guests": "visible to guests",
"voted {count} times": "voted {count} times",
"website": "website",
"welcome" : "Welcome, {0}",