#394 feature - Added user roles in form edition
| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.dao; |
|---|
| 2 | 2 | |
|---|
| 3 | +import java.util.Arrays; |
|---|
| 3 | 4 | import java.util.Date; |
|---|
| 4 | 5 | |
|---|
| 5 | 6 | import javax.inject.Inject; |
|---|
| .. | .. |
|---|
| 29 | 30 | user.setPassword(Utils.sha256("rob")); |
|---|
| 30 | 31 | user.setLang("en"); |
|---|
| 31 | 32 | user.setCreationTimestamp(new Date()); |
|---|
| 32 | | - user.setRoles(User.Rol.ADMIN | User.Rol.ADVANCE); |
|---|
| 33 | + user.setRoles(Arrays.asList(User.Rol.ADMIN, User.Rol.ADVANCE)); |
|---|
| 33 | 34 | user.setLastName("Sánchez"); |
|---|
| 34 | 35 | em.persist(user); |
|---|
| 35 | 36 | User u2 = em.find(User.class, username); |
|---|
| .. | .. |
|---|
| 88 | 88 | this.password = password; |
|---|
| 89 | 89 | } |
|---|
| 90 | 90 | |
|---|
| 91 | | - public int getRoles() { |
|---|
| 92 | | - return roles; |
|---|
| 91 | + public List<Integer> getRoles() { |
|---|
| 92 | + if (roles == 0) |
|---|
| 93 | + return null; |
|---|
| 94 | + List<Integer> aux = new ArrayList<>(); |
|---|
| 95 | + for (int rol : Rol.ALL) { |
|---|
| 96 | + if ((roles & rol) != 0) // Each rol is a number with only 1 bit == 1 in binary representation |
|---|
| 97 | + aux.add(rol); |
|---|
| 98 | + } |
|---|
| 99 | + return aux; |
|---|
| 93 | 100 | } |
|---|
| 94 | 101 | |
|---|
| 95 | | - public void setRoles(int roles) { |
|---|
| 96 | | - this.roles = roles; |
|---|
| 102 | + public void setRoles(List<Integer> roles) { |
|---|
| 103 | + this.roles = 0; |
|---|
| 104 | + if (roles != null) |
|---|
| 105 | + for (Integer rol : roles) { |
|---|
| 106 | + this.roles |= rol; |
|---|
| 107 | + } |
|---|
| 97 | 108 | } |
|---|
| 98 | 109 | |
|---|
| 99 | 110 | public String getFirstName() { |
|---|
| .. | .. |
|---|
| 181 | 192 | static public class Rol { |
|---|
| 182 | 193 | static public final int ADVANCE = 0x01; |
|---|
| 183 | 194 | static public final int ADMIN = 0x02; |
|---|
| 195 | + static public final int[] ALL = new int[] |
|---|
| 196 | + { ADVANCE, ADMIN }; |
|---|
| 184 | 197 | } |
|---|
| 185 | 198 | |
|---|
| 186 | 199 | } |
|---|
| .. | .. |
|---|
| 140 | 140 | _current.fields.forEach(function(f) { |
|---|
| 141 | 141 | if (f.resource) |
|---|
| 142 | 142 | refsFields.push(f) |
|---|
| 143 | + |
|---|
| 143 | 144 | }); |
|---|
| 144 | 145 | |
|---|
| 145 | 146 | var that = this; |
|---|
| .. | .. |
|---|
| 153 | 154 | console.log('promises: ' + promises.length + ' ') |
|---|
| 154 | 155 | console.log(promises) |
|---|
| 155 | 156 | $q.all(promises).then(function() { |
|---|
| 157 | + |
|---|
| 156 | 158 | for (var k in refs) { |
|---|
| 157 | 159 | var pk = that.getPk(that.getMetadata(that.getField(k).resource)) |
|---|
| 158 | 160 | console.log('PK field for ' + k + ' is ' + pk) |
|---|
| .. | .. |
|---|
| 167 | 169 | console.log('Ready for combo for ' + k) |
|---|
| 168 | 170 | console.log(comboData); |
|---|
| 169 | 171 | } |
|---|
| 170 | | - |
|---|
| 172 | + _current.fields.forEach(function(f) { |
|---|
| 173 | + if (f.values) |
|---|
| 174 | + refs[f.name] = f.values; |
|---|
| 175 | + }); |
|---|
| 171 | 176 | }) |
|---|
| 177 | + |
|---|
| 178 | + console.log(refs); |
|---|
| 172 | 179 | return refs; |
|---|
| 173 | 180 | } |
|---|
| 174 | 181 | |
|---|
| .. | .. |
|---|
| 152 | 152 | "resource" : "organization", |
|---|
| 153 | 153 | "type" : "multiselect" |
|---|
| 154 | 154 | }, { |
|---|
| 155 | + "name" : "roles", |
|---|
| 156 | + "display" : "Roles", |
|---|
| 157 | + "values" : [{"id":1, "label":"Advance"}, {"id":2, "label":"Admin"}], |
|---|
| 158 | + "type" : "multiselect" |
|---|
| 159 | + }, { |
|---|
| 155 | 160 | "name" : "lastLogin", |
|---|
| 156 | 161 | "display" : "Last login", |
|---|
| 157 | 162 | "autogenerate" : true, |
|---|