Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add per-user permissions.

  • Loading branch information...
commit add1d87e5a4e0a023f44da034c784812ef898d8a 1 parent e6cb34a
@pledbrook pledbrook authored
View
3  fixtures/users.groovy
@@ -11,7 +11,8 @@ fixture {
login: "peter",
password: DigestUtils.shaHex("password"),
email: "peter@somewhere.net",
- roles: [ observer, editor ])
+ roles: [ observer, editor ],
+ permissions: ["plugin:publish:shiro"])
dilbert(User,
login: "dilbert",
View
2  grails-app/domain/org/grails/auth/User.groovy
@@ -5,7 +5,7 @@ class User {
String login
String password
- static hasMany = [roles:Role]
+ static hasMany = [roles:Role, permissions:String]
static constraints = {
email email: true, unique: true, blank: false
View
2  grails-app/services/org/grails/auth/UserService.groovy
@@ -6,6 +6,6 @@ class UserService {
@Cacheable("permissions")
def permissionsForUser(principal) {
def user = User.findByLogin(principal)
- return user.roles*.permissions.inject([] as Set) { set, permList -> set.addAll permList; set }
+ return (user.permissions ?: []) + (user.roles*.permissions?.flatten() ?: []).unique()
}
}
View
15 migrations/changelog-1.2.groovy
@@ -54,4 +54,19 @@ databaseChangeLog = {
}
}
+ changeSet(author: "pledbrook (generated)", id: "1330711514540-1") {
+ createTable(tableName: "user_permissions") {
+ column(name: "user_id", type: "bigint")
+
+ column(name: "permissions_string", type: "varchar(255)")
+ }
+
+ createIndex(indexName: "FKE693E6101ADE5676", tableName: "user_permissions") {
+ column(name: "user_id")
+ }
+
+ createIndex(indexName: "FK919B5AFB2D0CED0B", tableName: "plugin_release") {
+ column(name: "plugin_id")
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.