01: /**********************************************************************************
02: * $URL: $
03: * $Id: $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006,2007 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.poll.tool.params;
21:
22: import java.util.HashMap;
23: import java.util.Iterator;
24: import java.util.Map;
25: import java.util.Set;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.sakaiproject.authz.cover.AuthzGroupService;
30: import org.sakaiproject.authz.api.AuthzGroup;
31: import org.sakaiproject.authz.api.Role;
32: import org.sakaiproject.tool.cover.ToolManager;
33: import org.sakaiproject.poll.logic.PollListManager;
34:
35: public class RoleFactory {
36:
37: private static Log m_log = LogFactory.getLog(RoleFactory.class);
38:
39: public Map getRoles() {
40: m_log.debug("Getting permRoles");
41: Map perms = new HashMap();
42: try {
43: AuthzGroup group = AuthzGroupService.getAuthzGroup("/site/"
44: + ToolManager.getCurrentPlacement().getContext());
45: Set roles = group.getRoles();
46: Iterator i = roles.iterator();
47:
48: while (i.hasNext()) {
49: Role role = (Role) i.next();
50: String name = role.getId();
51: m_log.debug("Adding element for " + name);
52: perms
53: .put(
54: name,
55: new PollRolePerms(
56: name,
57: role
58: .isAllowed(PollListManager.PERMISSION_VOTE),
59: role
60: .isAllowed(PollListManager.PERMISSION_ADD),
61: role
62: .isAllowed(PollListManager.PERMISSION_DELETE_OWN),
63: role
64: .isAllowed(PollListManager.PERMISSION_DELETE_ANY),
65: role
66: .isAllowed(PollListManager.PERMISSION_EDIT_OWN),
67: role
68: .isAllowed(PollListManager.PERMISSION_EDIT_ANY)));
69: }
70: } catch (Exception e) {
71: e.printStackTrace();
72: }
73: return perms;
74: }
75: }
|