001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/MemberPermissionWebHandler.java,v 1.37 2007/12/17 09:09:41 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.37 $
005: * $Date: 2007/12/17 09:09:41 $
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.MvnCoreServiceFactory;
052: import net.myvietnam.mvncore.service.EventLogService;
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 MemberPermissionWebHandler {
060: private OnlineUserManager onlineUserManager = OnlineUserManager
061: .getInstance();
062:
063: private static Log log = LogFactory
064: .getLog(MemberPermissionWebHandler.class);
065:
066: private static EventLogService eventLogService = MvnCoreServiceFactory
067: .getMvnCoreService().getEventLogService();
068:
069: public MemberPermissionWebHandler() {
070: }
071:
072: public void prepareListPermission(GenericRequest request)
073: throws DatabaseException, BadInputException,
074: ObjectNotFoundException, AuthenticationException {
075:
076: OnlineUser onlineUser = onlineUserManager
077: .getOnlineUser(request);
078: MVNForumPermission permission = onlineUser.getPermission();
079: permission.ensureCanAdminSystem();
080:
081: int memberID = GenericParamUtil.getParameterInt(request,
082: "memberid");
083:
084: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
085: memberID);
086: ArrayList memberPermissionBeans = (ArrayList) DAOFactory
087: .getMemberPermissionDAO().getBeans_inMember(memberID);
088:
089: int currentSize = memberPermissionBeans.size();
090: int[] currentPermissions = new int[currentSize];
091:
092: for (int i = 0; i < currentSize; i++) {
093: MemberPermissionBean memberPermissionBean = (MemberPermissionBean) memberPermissionBeans
094: .get(i);
095: currentPermissions[i] = memberPermissionBean
096: .getPermission();
097: }
098:
099: request.setAttribute("MemberBean", memberBean);
100: request.setAttribute("CurrentPermissions", currentPermissions);
101: }
102:
103: public void processUpdate(GenericRequest request)
104: throws CreateException, ObjectNotFoundException,
105: BadInputException, DatabaseException,
106: DuplicateKeyException, ForeignKeyNotFoundException,
107: AuthenticationException {
108:
109: SecurityUtil.checkHttpPostMethod(request);
110:
111: OnlineUser onlineUser = onlineUserManager
112: .getOnlineUser(request);
113: MVNForumPermission permission = onlineUser.getPermission();
114: permission.ensureCanAdminSystem();
115:
116: Locale locale = I18nUtil.getLocaleInRequest(request);
117:
118: String btnAction = GenericParamUtil.getParameter(request,
119: "btnAction");
120: boolean addAction = false;
121:
122: if (btnAction.equals("Add")) {
123: addAction = true;
124: } else if (btnAction.equals("Remove")) {
125: addAction = false;
126: } else {
127: String localizedMessage = MVNForumResourceBundle
128: .getString(
129: locale,
130: "mvncore.exception.BadInputException.cannot_process.no_add_or_remove_is_specified");
131: throw new BadInputException(localizedMessage);
132: }
133:
134: int memberID = GenericParamUtil.getParameterInt(request,
135: "memberid");
136:
137: if (addAction) {
138: log.debug("Add List");
139: String[] addList = request.getParameterValues("add");
140: for (int i = 0; (addList != null) && (i < addList.length); i++) {
141: int perm = Integer.parseInt(addList[i]);
142: log.debug("perm = " + perm);
143: DAOFactory.getMemberPermissionDAO().create(memberID,
144: perm);
145: }
146: } else {
147: log.debug("Remove List");
148: String[] removeList = request.getParameterValues("remove");
149: for (int i = 0; (removeList != null)
150: && (i < removeList.length); i++) {
151: int perm = Integer.parseInt(removeList[i]);
152: log.debug("perm = " + removeList[i]);
153: if ((MyUtil.isRootAdminID(memberID))
154: && (perm == MVNForumPermission.PERMISSION_SYSTEM_ADMIN)) {
155: // We dont remove the SystemAdmin permission from the administator with id = 1
156: } else {
157: DAOFactory.getMemberPermissionDAO().delete(
158: memberID, perm);
159: }
160: }
161: } //else
162:
163: String actionDesc = MVNForumResourceBundle.getString(
164: MVNForumConfig.getEventLogLocale(),
165: "mvnforum.eventlog.desc.UpdateMemberPermission",
166: new Object[] { new Integer(memberID) });
167: eventLogService.logEvent(onlineUser.getMemberName(), request
168: .getRemoteAddr(),
169: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
170: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
171: "update member permission", actionDesc,
172: EventLogService.MEDIUM);
173:
174: }
175:
176: }
|