001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-impl/standalone/src/java/org/sakaiproject/component/section/facade/impl/standalone/AuthzStandaloneImpl.java $
003: * $Id: AuthzStandaloneImpl.java 19769 2006-12-19 20:49:32Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.section.facade.impl.standalone;
021:
022: import java.sql.SQLException;
023:
024: import org.hibernate.HibernateException;
025: import org.hibernate.Query;
026: import org.hibernate.Session;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.section.api.coursemanagement.ParticipationRecord;
031: import org.sakaiproject.section.api.facade.Role;
032: import org.sakaiproject.section.api.facade.manager.Authz;
033: import org.springframework.orm.hibernate3.HibernateCallback;
034: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
035:
036: /**
037: * A standalone, hibernate-based implementation of the Authz facade.
038: *
039: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
040: *
041: */
042: public class AuthzStandaloneImpl extends HibernateDaoSupport implements
043: Authz {
044: private static final Log log = LogFactory
045: .getLog(AuthzStandaloneImpl.class);
046:
047: private Role getSiteRole(final String userUid,
048: final String siteContext) {
049: HibernateCallback hc = new HibernateCallback() {
050: public Object doInHibernate(Session session)
051: throws HibernateException, SQLException {
052: Query q = session
053: .getNamedQuery("loadSiteParticipation");
054: q.setParameter("userUid", userUid);
055: q.setParameter("siteContext", siteContext);
056: return q.uniqueResult();
057: }
058: };
059: Object result = getHibernateTemplate().execute(hc);
060: if (result == null) {
061: if (log.isDebugEnabled())
062: log
063: .debug(userUid
064: + " is not a member of the course at site context "
065: + siteContext);
066: return Role.NONE;
067: }
068: return ((ParticipationRecord) result).getRole();
069: }
070:
071: public boolean isSectionManagementAllowed(String userUid,
072: String siteContext) {
073: Role role = getSiteRole(userUid, siteContext);
074: return role.isInstructor();
075: }
076:
077: public boolean isSectionOptionsManagementAllowed(String userUid,
078: String siteContext) {
079: return isSectionManagementAllowed(userUid, siteContext);
080: }
081:
082: public boolean isSectionEnrollmentMangementAllowed(String userUid,
083: String siteContext) {
084: Role role = getSiteRole(userUid, siteContext);
085: return role.isInstructor() || role.isTeachingAssistant();
086: }
087:
088: public boolean isSectionTaManagementAllowed(String userUid,
089: String siteContext) {
090: return isSectionManagementAllowed(userUid, siteContext);
091: }
092:
093: public boolean isViewOwnSectionsAllowed(String userUid,
094: String siteContext) {
095: Role role = getSiteRole(userUid, siteContext);
096: return role.isStudent();
097: }
098:
099: public boolean isViewAllSectionsAllowed(String userUid,
100: String siteContext) {
101: Role role = getSiteRole(userUid, siteContext);
102: return role.isInstructor() || role.isTeachingAssistant();
103: }
104:
105: public boolean isSectionAssignable(String userUid,
106: String siteContext) {
107: Role role = getSiteRole(userUid, siteContext);
108: return role.isTeachingAssistant() || role.isStudent();
109: }
110:
111: public String getRoleDescription(String userUid, String siteContext) {
112: Role role = getSiteRole(userUid, siteContext);
113: if (role.isInstructor()) {
114: return "Instructor";
115: } else if (role.isStudent()) {
116: return "Student";
117: } else if (role.isTeachingAssistant()) {
118: return "Teaching Assistant";
119: } else {
120: return null;
121: }
122: }
123:
124: }
|