Author: vdichev
Date: Thu Jun 11 22:52:45 2009
New Revision: 783953
URL: http://svn.apache.org/viewvc?rev=783953&view=rev
Log:
ESME-56 Web UI for setting permissions to a user in an access pool
Added:
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
(with props)
Modified:
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/Privilege.scala
incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html
Added:
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala?rev=783953&view=auto
==============================================================================
---
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
(added)
+++
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
Thu Jun 11 22:52:45 2009
@@ -0,0 +1,127 @@
+/**
+ * Copyright 2008-2009 WorldWide Conferencing, LLC
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.esme.lib
+
+import net.liftweb._
+import http._
+import SHtml._
+import js._
+import JsCmds._
+import JE._
+
+import sitemap._
+import Loc._
+
+import mapper._
+
+import util._
+import Helpers._
+
+import model._
+import org.apache.esme.actor.Distributor
+
+import scala.xml._
+
+/**
+ * Manage the sitemap and related snippets for Access Pools
+ */
+object AccessPoolMgr {
+ def loggedIn_? = User.loggedIn_?
+
+ val ifIsLoggedIn = If(loggedIn_? _, strFuncToFailMsg(() => S.?("You must be
logged in")))
+
+ val menuItems =
+ Menu(Loc("accessPools", List("pools_view", "index"), "Manage Access Pools",
ifIsLoggedIn,
+ Loc.Snippet("addPool", addPool),
+ Loc.Snippet("editPool", editPool))) ::
+ Nil
+
+ def addPool(in: NodeSeq): NodeSeq = {
+ val theInput = "new_pool"
+ val user = User.currentUser
+
+ def addNewPool(name: String) = {
+ name.trim match {
+ case x if x.length < 3 => S.error("Name too short")
+ case x => {
+ val pool = AccessPool.create.realm("Native").setName(name)
+ pool match {
+ case Failure(_,_,_) => S.error("Duplicate pool name!")
+ case Full(p: AccessPool) => val privilegeSaved =
+
Privilege.create.pool(p.saveMe).user(user).permission(Permission.Admin).save
+ if(privilegeSaved)
+ S.notice("New pool added")
+ else
+ S.error("Could not add pool!")
+ }
+ }
+ }
+
+ }
+
+ bind("add", in,
+ "poolName" -> text("", addNewPool, "id" -> theInput)
+ )
+
+ }
+
+ def editPool(in: NodeSeq): NodeSeq = {
+ var pool = ""
+ var username = ""
+ val editPoolName = "edit_pool"
+ val editUsername = "edit_username"
+ val editPermission = "edit_permission"
+ val adminUser = User.currentUser
+
+ val adminPools = adminUser match {
+ case Full(u)=> Privilege.findAdminPools(u.id).map(
+ p => (p.toString, AccessPool.find(p).get.getName))
+ case _ => Nil
+ }
+
+ val permissions = Permission.map(perm => (perm.id.toString,
perm.toString)).collect
+
+ def addUserPool(permission: String) = {
+ val r: Box[Boolean] =
+ for (admin <- adminUser;
+ p <- AccessPool.find(pool) ?~ "Pool not found";
+ user <- User.findFromWeb(username) ?~ "User not found"
+ ) yield if(Privilege.hasPermission(admin.id.is, p.id.is,
Permission.Admin)) {
+ val result =
Privilege.create.user(user).pool(p).permission(Permission(permission.toInt)).save
+ if (result) Distributor ! Distributor.AllowUserInPool(user.id.is,
p.id.is)
+ result
+ } else false // "User has no permission to administer pool"
+ r match {
+ case Failure(m,_,_) => S.error(m)
+ case Full(true) => S.notice("Successfully set user privileges in pool")
+ case Full(false) => S.error("Could not set user privileges in pool")
+ }
+ }
+
+ bind("edit", in,
+ "pool" -> select(adminPools, Empty, pool = _, "id" -> editPoolName),
+ "username" -> text(username, username = _, "id" -> editUsername),
+ "permission" -> select(permissions, Empty, addUserPool, "id" ->
editPermission)
+ )
+
+ }
+}
Propchange:
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
------------------------------------------------------------------------------
svn:executable = *
Modified:
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala?rev=783953&r1=783952&r2=783953&view=diff
==============================================================================
---
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
(original)
+++
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/AccessPool.scala
Thu Jun 11 22:52:45 2009
@@ -42,6 +42,7 @@
object id extends MappedLongIndex(this)
+ // is it worth having foreign key to another table?
object realm extends MappedString(this, 256)
private[model] object name extends MappedString(this, 256) {
Modified:
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/Privilege.scala
URL:
http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/Privilege.scala?rev=783953&r1=783952&r2=783953&view=diff
==============================================================================
---
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/Privilege.scala
(original)
+++
incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/model/Privilege.scala
Thu Jun 11 22:52:45 2009
@@ -43,6 +43,11 @@
By(Privilege.user, userId),
NotBy(Privilege.permission, Permission.Read)
)(p => Full(p.pool.is))
+
+ def findAdminPools(userId: Long) = Privilege.findMap(
+ By(Privilege.user, userId),
+ By(Privilege.permission, Permission.Admin)
+ )(p => Full(p.pool.is))
}
class Privilege extends LongKeyedMapper[Privilege] {
Modified:
incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html
URL:
http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html?rev=783953&r1=783952&r2=783953&view=diff
==============================================================================
---
incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html
(original)
+++
incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html
Thu Jun 11 22:52:45 2009
@@ -9,13 +9,13 @@
</lift:addPool>
</lift:form>
-<!-- <lift:form>
+ <lift:form>
<lift:editPool>
- Edit user permissions within pool: <edit:poolName/> <br/>
+ Edit user permissions within pool: <edit:pool/>
User name: <edit:username/> <edit:permission/>
<input type="submit" value="Edit" />
</lift:editPool>
- </lift:form>-->
+ </lift:form>
</lift:surround>