001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/GroupPermissionWebHandler.java,v 1.33 2007/12/17 09:09:40 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.33 $
005: * $Date: 2007/12/17 09:09:40 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: * @author: Mai Nguyen
040: */
041: package com.mvnforum.admin;
042:
043: import java.util.ArrayList;
044: import java.util.Locale;
045:
046: import com.mvnforum.*;
047: import com.mvnforum.auth.*;
048: import com.mvnforum.db.*;
049: import net.myvietnam.mvncore.exception.*;
050: import net.myvietnam.mvncore.security.SecurityUtil;
051: import net.myvietnam.mvncore.service.EventLogService;
052: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
053: import net.myvietnam.mvncore.util.GenericParamUtil;
054: import net.myvietnam.mvncore.util.I18nUtil;
055: import net.myvietnam.mvncore.web.GenericRequest;
056: import org.apache.commons.logging.Log;
057: import org.apache.commons.logging.LogFactory;
058:
059: public class GroupPermissionWebHandler {
060:
061: private static Log log = LogFactory
062: .getLog(GroupPermissionWebHandler.class);
063:
064: private OnlineUserManager onlineUserManager = OnlineUserManager
065: .getInstance();
066:
067: private static EventLogService eventLogService = MvnCoreServiceFactory
068: .getMvnCoreService().getEventLogService();
069:
070: public GroupPermissionWebHandler() {
071: }
072:
073: public void prepareList(GenericRequest request)
074: throws DatabaseException, BadInputException,
075: ObjectNotFoundException, AuthenticationException {
076:
077: OnlineUser onlineUser = onlineUserManager
078: .getOnlineUser(request);
079: MVNForumPermission permission = onlineUser.getPermission();
080: permission.ensureCanAdminSystem();
081:
082: int groupID = GenericParamUtil
083: .getParameterInt(request, "group");
084:
085: GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(
086: groupID);
087:
088: ArrayList groupPermissionBeans = (ArrayList) DAOFactory
089: .getGroupPermissionDAO().getBeans_inGroup(groupID);
090: int currentSize = groupPermissionBeans.size();
091: int[] currentPermissions = new int[currentSize];
092: for (int i = 0; i < currentSize; i++) {
093: GroupPermissionBean groupPermissionBean = (GroupPermissionBean) groupPermissionBeans
094: .get(i);
095: currentPermissions[i] = groupPermissionBean.getPermission();
096: }
097:
098: request.setAttribute("GroupsBean", groupsBean);
099: request.setAttribute("CurrentPermissions", currentPermissions);
100: }
101:
102: public void processUpdate(GenericRequest request)
103: throws CreateException, ObjectNotFoundException,
104: BadInputException, DatabaseException,
105: DuplicateKeyException, ForeignKeyNotFoundException,
106: AuthenticationException {
107:
108: SecurityUtil.checkHttpPostMethod(request);
109:
110: OnlineUser onlineUser = onlineUserManager
111: .getOnlineUser(request);
112: MVNForumPermission permission = onlineUser.getPermission();
113: permission.ensureCanAdminSystem();
114:
115: Locale locale = I18nUtil.getLocaleInRequest(request);
116:
117: String btnAction = GenericParamUtil.getParameter(request,
118: "btnAction");
119: boolean addAction = false;
120:
121: if (btnAction.equals("Add")) {
122: addAction = true;
123: } else if (btnAction.equals("Remove")) {
124: addAction = false;
125: } else {
126: String localizedMessage = MVNForumResourceBundle
127: .getString(
128: locale,
129: "mvncore.exception.BadInputException.cannot_process.no_add_or_remove_is_specified");
130: throw new BadInputException(localizedMessage);
131: }
132:
133: int groupID = GenericParamUtil
134: .getParameterInt(request, "group");
135:
136: if (addAction) {
137: log.debug("Add List");
138: String[] addList = request.getParameterValues("add");
139: for (int i = 0; (addList != null) && (i < addList.length); i++) {
140: int perm = Integer.parseInt(addList[i]);
141: log.debug("perm = " + perm);
142: DAOFactory.getGroupPermissionDAO()
143: .create(groupID, perm);
144: }
145: } else {
146: log.debug("Remove List");
147: String[] removeList = request.getParameterValues("remove");
148: for (int i = 0; (removeList != null)
149: && (i < removeList.length); i++) {
150: int perm = Integer.parseInt(removeList[i]);
151: log.debug("perm = " + removeList[i]);
152: DAOFactory.getGroupPermissionDAO()
153: .delete(groupID, perm);
154: }
155: }//else
156:
157: String actionDesc = MVNForumResourceBundle.getString(
158: MVNForumConfig.getEventLogLocale(),
159: "mvnforum.eventlog.desc.UpdateGroupPermission",
160: new Object[] { new Integer(groupID) });
161: eventLogService.logEvent(onlineUser.getMemberName(), request
162: .getRemoteAddr(),
163: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
164: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
165: "update group permission", actionDesc,
166: EventLogService.MEDIUM);
167:
168: }
169:
170: }
|