- Timestamp:
- Jan 25, 2010, 10:57:30 AM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/PersonController.groovy
r294 r295 42 42 return 43 43 } 44 List roleNames = [] 45 for (role in person.authorities) { 46 roleNames << role.authority 47 } 48 roleNames.sort { n1, n2 -> 49 n1 <=> n2 50 } 51 [person: person, roleNames: roleNames] 44 def authorityList = person.authorities.sort { p1, p2 -> p1.id <=> p2.id } 45 [person: person, authorityList: authorityList] 52 46 } 53 47 … … 138 132 139 133 if (!person.hasErrors() && person.save(flush: true)) { 140 addRemove Roles(person)134 addRemoveAuthorities(person) 141 135 flash.message = "Person '$params.id - $params.loginName' updated." 142 136 redirect action: show, id: person.id … … 165 159 person.setPersonGroupsFromCheckBoxList(params.personGroups) 166 160 if (person.save(flush: true)) { 167 addRemove Roles(person)161 addRemoveAuthorities(person) 168 162 redirect action: show, id: person.id 169 163 } … … 175 169 } 176 170 177 private void addRemoveRoles(person) { 171 /** 172 * Add or remove authorities from person as indicated in params. 173 */ 174 private void addRemoveAuthorities(person) { 175 def authMap = [:] 176 177 // Build authMap from params. 178 178 for (key in params.keySet()) { 179 if(key.startsWith("ROLE")) 180 Authority.findByAuthority(key).addToPersons(person) 181 else if(key.startsWith("_ROLE")) 182 Authority.findByAuthority(key.substring(1)).removeFromPersons(person) 179 if(key.startsWith("ROLE")) { 180 authMap.(key.toString()) = "add" 181 } 182 else if(key.startsWith("_ROLE")) { 183 if( !authMap.(key.substring(1)) ) authMap.(key.substring(1)) = "remove" 184 } 185 } 186 187 // Add or remove authorities. 188 for(a in authMap) { 189 if(a.value == "add") 190 Authority.findByAuthority(a.key.toString()).addToPersons(person) 191 else 192 Authority.findByAuthority(a.key.toString()).removeFromPersons(person) 183 193 } 184 194 } … … 187 197 188 198 List roles = getLimitedAuthorityList() 189 roles.sort { r1, r2 ->190 r1.authority <=> r2.authority191 }192 199 Set userRoleNames = [] 193 200 for (role in person.authorities) { … … 205 212 * Get the full authorityList if current user is an App Admin else leave that authority off the list. 206 213 */ 207 def getLimitedAuthorityList ={214 private List getLimitedAuthorityList() { 208 215 def authorityList = [] 209 216 if(authenticateService.ifAnyGranted('ROLE_AppAdmin')) 210 authorityList = Authority.list().sort { p1, p2 -> p1. authority.compareToIgnoreCase(p2.authority)}217 authorityList = Authority.list().sort { p1, p2 -> p1.id <=> p2.id } 211 218 else 212 authorityList = Authority.withCriteria { gt("id", 1L) }.sort { p1, p2 -> p1. authority.compareToIgnoreCase(p2.authority)}219 authorityList = Authority.withCriteria { gt("id", 1L) }.sort { p1, p2 -> p1.id <=> p2.id } 213 220 214 221 return authorityList 215 222 } 216 } 223 } // end class -
trunk/grails-app/views/person/create.gsp
r294 r295 130 130 <g:each in="${authorityList}"> 131 131 <tr> 132 <td valign="top" class="name" align="left">${it. authority.encodeAsHTML()}</td>132 <td valign="top" class="name" align="left">${it.description.encodeAsHTML()}</td> 133 133 <td align="left"> 134 134 <g:checkBox name="${it.authority}" value="${it.authority == 'ROLE_AppUser'}"/> -
trunk/grails-app/views/person/edit.gsp
r294 r295 137 137 <g:each var="entry" in="${roleMap}"> 138 138 <tr> 139 <td valign="top" class="name" align="left">${entry.key. authority.encodeAsHTML()}</td>139 <td valign="top" class="name" align="left">${entry.key.description.encodeAsHTML()}</td> 140 140 <td align="left"><g:checkBox name="${entry.key.authority}" value="${entry.value}"/></td> 141 141 </tr> -
trunk/grails-app/views/person/show.gsp
r166 r295 84 84 <td valign="top" class="value"> 85 85 <ul> 86 <g:each in="${roleNames}" var='name'>87 <li>${ name}</li>86 <g:each var='a' in="${authorityList}"> 87 <li>${a.description.encodeAsHTML()}</li> 88 88 </g:each> 89 89 </ul>
Note: See TracChangeset
for help on using the changeset viewer.