working on poll permissions

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-03-04 23:17:09 +01:00
parent 02d0f829c8
commit 702b9dadd5
11 changed files with 126 additions and 48 deletions

View File

@@ -31,10 +31,11 @@ public class Path {
public static final String OPTION = "option";
public static final String PAGE = "page";
public static final String PASSWORD = "password";
public static final String PROJECT = "project";
public static final String PROPERTIES = "properties";
public static final String PAGE = "page";
public static final String PASSWORD = "password";
public static final String PERMISSIONS = "permissions";
public static final String PROJECT = "project";
public static final String PROPERTIES = "properties";
public static final String PROPERTY = "property";
public static final String READ = "read";

View File

@@ -49,6 +49,7 @@ public class Text {
public static final Object OPTION = "option"
;
public static final String PATH = "path";
public static final String PERMISSION = "permission";
public static final String POLL = "poll";
public static final String POLLS = "polls";
public static final String PROJECTS = "projects";

View File

@@ -31,7 +31,7 @@ public enum Permission implements Mappable {
for (var p : Permission.values()){
if (p.code == code) return p;
}
throw new InvalidParameterException(format("{0} is not a valid permission code"));
throw new InvalidParameterException(format("{0} is not a valid permission code",code));
}
@Override

View File

@@ -18,6 +18,7 @@ public class Poll implements Mappable {
public static class Option implements Mappable{
private int id;
Integer status;
private String description;
private String name;
@@ -28,7 +29,6 @@ public class Poll implements Mappable {
this.description = description;
this.status = status;
}
public String description(){
return description;
}
@@ -104,11 +104,11 @@ public class Poll implements Mappable {
return format("Option \"{0}\"",name);
}
}
public static class Evaluation {
// Map<Option → Map<Weight → Count>>
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);
@@ -120,16 +120,17 @@ public class Poll implements Mappable {
public HashMap<Integer, Map<Integer, Integer>> toMap() {
return selections;
}
}
private Owner owner;
private String id, name, description;
private boolean isPrivate;
private List<Option> options;
private Map<Integer,String> weights;
private Map<UmbrellaUser,Long> shares;
private Map<UmbrellaUser,Permission> permissions;
private Set<String> dirtyFields = new HashSet<>();
public Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights, Map<UmbrellaUser,Long> shares){
public Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights){
this.id = id;
this.owner = owner;
this.name = name;
@@ -137,9 +138,8 @@ public class Poll implements Mappable {
this.isPrivate = isPrivate;
this.options = new ArrayList<>();
this.weights = new HashMap<>();
this.shares = new HashMap<>();
this.permissions = new HashMap<>();
}
public String description(){
return description;
}
@@ -169,12 +169,12 @@ public class Poll implements Mappable {
return isPrivate;
}
private Map<Long, Map<String, Object>> mapShares() {
private Map<Long, Map<String, Object>> mapPermissions() {
var result = new HashMap<Long,Map<String,Object>>();
for (var entry : shares.entrySet()){
for (var entry : permissions.entrySet()){
var user = entry.getKey();
var data = user.toMap();
data.put(Field.PERMISSION,entry.getValue());
data.put(Field.PERMISSION,entry.getValue().toMap());
result.put(user.id(),data);
}
return result;
@@ -198,7 +198,7 @@ public class Poll implements Mappable {
var isPrivate = rs.getBoolean(Field.PRIVATE);
var owner = ModuleRegistry.userService().loadUser(userId);
return new Poll(id,owner,name,description,isPrivate,new ArrayList<>(),new HashMap<>(),new HashMap<>());
return new Poll(id,owner,name,description,isPrivate,new ArrayList<>(),new HashMap<>());
}
public List<Option> options(){
@@ -209,14 +209,20 @@ public class Poll implements Mappable {
return owner;
}
public Poll setPrivate(boolean newValue) {
if (newValue != isPrivate) dirtyFields.add(PRIVATE);
isPrivate = newValue;
return this;
}
public Poll setWeight(Integer weight, String description) {
weights.put(weight,description);
dirtyFields.add(WEIGHTS);
return this;
}
public Map<UmbrellaUser, Long> shares(){
return shares;
public Map<UmbrellaUser, Permission> permissions(){
return permissions;
}
@Override
@@ -230,7 +236,7 @@ public class Poll implements Mappable {
Field.RENDERED,Util.markdown(description)
),
Field.OPTIONS, options.stream().collect(Collectors.toMap(Option::id,Option::toMap)),
Field.SHARES, mapShares(),
Field.PERMISSION, mapPermissions(),
Field.PRIVATE, isPrivate,
Field.WEIGHTS, weights
);