Skip to content

Instantly share code, notes, and snippets.

@k4200
Created July 10, 2011 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/1074400 to your computer and use it in GitHub Desktop.
Save k4200/1074400 to your computer and use it in GitHub Desktop.
A trait that can be mixed in a model that only admin users can do CRUD
// This file is distributed under the same license as that of Lift.
//
package com.example {
package lib {
import net.liftweb._
import common._;
import http._;
import mapper._
import sitemap._;
import Loc._;
import proto.{ProtoUser => GenProtoUser}
//import util.Helpers.tryo
trait AdminEditableCRUDify [KeyType,
CrudType <: AdminEditableKeyedMapper[KeyType, CrudType]]
extends MegaCRUDify [KeyType, CrudType] {
self: CrudType with KeyedMetaMapper[KeyType, CrudType] =>
val superUser_? = If(() => self.userObject.superUser_? ,
() => RedirectResponse("/user_mgt/login"));
override def showAllMenuLocParams: List[Loc.AnyLocParam] = List(superUser_?);
override def viewMenuLocParams: List[Loc.AnyLocParam] = List(superUser_?)
override def createMenuLocParams: List[Loc.AnyLocParam] = List(superUser_?);
override def editMenuLocParams: List[Loc.AnyLocParam] = List(superUser_?);
override def deleteMenuLocParams: List[Loc.AnyLocParam] = List(superUser_?);
//override def deleteMenuLoc: Box[Menu] = Empty;
}
trait AdminEditableKeyedMapper[KeyType, OwnerType <: KeyedMapper[KeyType, OwnerType]]
extends KeyedMapper[KeyType, OwnerType] {
self: OwnerType =>
val userObject: GenProtoUser
}
}
}
@k4200
Copy link
Author

k4200 commented Jul 10, 2011

MegaCRUDify is here.
https://gist.github.com/1074403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment