alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/MVNForumPermissionImpl.java,v 1.8 2005/01/18 11:52:15 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.8 $
 * $Date: 2005/01/18 11:52:15 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2005 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package com.mvnforum.auth;

import net.myvietnam.mvncore.exception.AssertionException;

/**
 * This class is private in the package
 */
class MVNForumPermissionImpl extends AbstractPermission implements MVNForumPermission {

    MVNForumPermissionImpl() {
    }

    private void setBypassPrivateForum(boolean bypass) {
        editForum.setBypassPrivateForum(bypass);
        deleteForum.setBypassPrivateForum(bypass);
        assignToForum.setBypassPrivateForum(bypass);

        readPost.setBypassPrivateForum(bypass);
        addThread.setBypassPrivateForum(bypass);
        addPost.setBypassPrivateForum(bypass);
        editPost.setBypassPrivateForum(bypass);
        deletePost.setBypassPrivateForum(bypass);
        addPoll.setBypassPrivateForum(bypass);
        editPoll.setBypassPrivateForum(bypass);
        deletePoll.setBypassPrivateForum(bypass);
        addAttachment.setBypassPrivateForum(bypass);
        getAttachment.setBypassPrivateForum(bypass);
        moderateThread.setBypassPrivateForum(bypass);
    }

    /**
     * The ONLY way to set permission, so this MUST have default package access
     */
    void setPermission(int permission) throws AssertionException {
        switch (permission) {
            case PERMISSION_AUTHENTICATED:
                authenticated   = true;
                break;

            case PERMISSION_ACTIVATED:
                activated   = true;
                break;
/**************************************************************************
 * Combined permissions, range from 100 to 199
 * A permission in this range is the combination of other permissions
 **************************************************************************/
            case PERMISSION_SYSTEM_ADMIN:
                adminSystem          = true;
                addForum             = true;
                editForum.setAllForumsPermission(true);
                deleteForum.setAllForumsPermission(true);
                assignToForum.setAllForumsPermission(true);
                addCategory          = true;
                editCategory         = true;
                deleteCategory       = true;
                sendMail             = true;
                useAvatar            = true;
                useMessage           = true;
                addMessageAttachment = true;

                readPost.setAllForumsPermission(true);
                addThread.setAllForumsPermission(true);
                addPost.setAllForumsPermission(true);
                editPost.setAllForumsPermission(true);
                deletePost.setAllForumsPermission(true);
                addPoll.setAllForumsPermission(true);
                editPoll.setAllForumsPermission(true);
                deletePoll.setAllForumsPermission(true);
                addAttachment.setAllForumsPermission(true);
                getAttachment.setAllForumsPermission(true);
                moderateThread.setAllForumsPermission(true);

                setBypassPrivateForum(true);
                break;

            case PERMISSION_FORUM_ADMIN:
                addForum        = true;
                editForum.setAllForumsPermission(true);
                deleteForum.setAllForumsPermission(true);
                assignToForum.setAllForumsPermission(true);
                addCategory     = true;
                editCategory    = true;
                deleteCategory  = true;

                readPost.setAllForumsPermission(true);
                addThread.setAllForumsPermission(true);
                addPost.setAllForumsPermission(true);
                editPost.setAllForumsPermission(true);
                deletePost.setAllForumsPermission(true);
                addPoll.setAllForumsPermission(true);
                editPoll.setAllForumsPermission(true);
                deletePoll.setAllForumsPermission(true);
                addAttachment.setAllForumsPermission(true);
                getAttachment.setAllForumsPermission(true);
                moderateThread.setAllForumsPermission(true);
                break;

            case PERMISSION_FORUM_MODERATOR:
                editForum.setAllForumsPermission(true);
                editCategory    = true;

                readPost.setAllForumsPermission(true);
                addThread.setAllForumsPermission(true);
                addPost.setAllForumsPermission(true);
                editPost.setAllForumsPermission(true);
                deletePost.setAllForumsPermission(true);
                addPoll.setAllForumsPermission(true);
                editPoll.setAllForumsPermission(true);
                deletePoll.setAllForumsPermission(true);
                addAttachment.setAllForumsPermission(true);
                getAttachment.setAllForumsPermission(true);
                moderateThread.setAllForumsPermission(true);
                break;

            case PERMISSION_LIMITED_USER:
                readPost.setAllForumsPermission(true);
                /** @todo at the 1.0.0 beta2/beta3/RC1/RC2 release, add post is disable*/
//                addPost         = true;
                break;

            case PERMISSION_NORMAL_USER:
                useAvatar       = true;
                useMessage      = true;

                readPost.setAllForumsPermission(true);
                addThread.setAllForumsPermission(true);
                addPost.setAllForumsPermission(true);
                getAttachment.setAllForumsPermission(true);
                break;

            /**
             * Can:
             * - login, read thread and post, reply to a thread
             * - add thread, use avatar, use private message, get attachment
             * - use attachment, create poll
             */
            case PERMISSION_POWER_USER:
                useAvatar            = true;
                useMessage           = true;
                addMessageAttachment = true;

                readPost.setAllForumsPermission(true);
                addThread.setAllForumsPermission(true);
                addPost.setAllForumsPermission(true);
                addPoll.setAllForumsPermission(true);
                addAttachment.setAllForumsPermission(true);
                getAttachment.setAllForumsPermission(true);
                break;

/**************************************************************************
 * Individual Permissions for global usages, range from 1000 to 2000
 **************************************************************************/
            case PERMISSION_LOGIN:
                login           = true;
                break;
            //case PERMISSION_ADMIN_SYSTEM:
            //    adminSystem     = true;
            //    break;
            case PERMISSION_ADD_FORUM:
                addForum          = true;
                break;
            case PERMISSION_ADD_CATEGORY:
                addCategory     = true;
                break;
            case PERMISSION_EDIT_CATEGORY:
                editCategory    = true;
                break;
            case PERMISSION_DELETE_CATEGORY:
                deleteCategory  = true;
                break;
            case PERMISSION_SEND_MAIL:
                sendMail        = true;
                break;
            case PERMISSION_BYPASS_PRIVATE_FORUM:
                setBypassPrivateForum(true);
                break;
            case PERMISSION_USE_MESSAGE:
                useMessage      = true;
                break;
            case PERMISSION_ADD_MESSAGE_ATTACHMENT:
                addMessageAttachment = true;
                break;
            case PERMISSION_USE_AVATAR:
                useAvatar       = true;
                break;

/**************************************************************************
 * Individual Permissions that can be applied for individual forum usages,
 * (of course it can be applied to all forums), range from 2000 to 3000
 **************************************************************************/
            case PERMISSION_EDIT_FORUM:
                editForum.setAllForumsPermission(true);
                break;
            case PERMISSION_DELETE_FORUM:
                deleteForum.setAllForumsPermission(true);
                break;
            case PERMISSION_ASSIGN_TO_FORUM:
                assignToForum.setAllForumsPermission(true);
                break;
            case PERMISSION_READ_POST:
                readPost.setAllForumsPermission(true);
                break;
            case PERMISSION_ADD_THREAD:
                addThread.setAllForumsPermission(true);
                break;
            case PERMISSION_ADD_POST:
                addPost.setAllForumsPermission(true);
                break;
            case PERMISSION_EDIT_POST:
                editPost.setAllForumsPermission(true);
                break;
            case PERMISSION_DELETE_POST:
                deletePost.setAllForumsPermission(true);
                break;
            case PERMISSION_ADD_POLL:
                addPoll.setAllForumsPermission(true);
                break;
            case PERMISSION_EDIT_POLL:
                editPoll.setAllForumsPermission(true);
                break;
            case PERMISSION_DELETE_POLL:
                deletePoll.setAllForumsPermission(true);
                break;
            case PERMISSION_ADD_ATTACHMENT:
                addAttachment.setAllForumsPermission(true);
                break;
            case PERMISSION_GET_ATTACHMENT:
                getAttachment.setAllForumsPermission(true);
                break;
            case PERMISSION_MODERATE_THREAD:
                moderateThread.setAllForumsPermission(true);
                break;

/**************************************************************************
 * cannot find, just throw an Exception
 **************************************************************************/

            default:
                throw new AssertionException("Currently in setPermission do not support permission = " + permission);
        }//switch
    }//setPermission

    /**
     * The ONLY way to set permission in forum, so this MUST have default package access
     */
    void setPermissionInForum(int forumID, int permission) throws AssertionException {
        switch (permission) {
/**************************************************************************
 * Combined permissions, range from 100 to 199
 * A permission in this range is the combination of other permissions
 **************************************************************************/
            case PERMISSION_FORUM_ADMIN:
                editForum.setForumPermission(forumID, true);
                deleteForum.setForumPermission(forumID, true);
                assignToForum.setForumPermission(forumID, true);

                readPost.setForumPermission(forumID, true);
                addThread.setForumPermission(forumID, true);
                addPost.setForumPermission(forumID, true);
                editPost.setForumPermission(forumID, true);
                deletePost.setForumPermission(forumID, true);
                addPoll.setForumPermission(forumID, true);
                editPoll.setForumPermission(forumID, true);
                deletePoll.setForumPermission(forumID, true);
                addAttachment.setForumPermission(forumID, true);
                getAttachment.setForumPermission(forumID, true);
                moderateThread.setForumPermission(forumID, true);
                break;

            case PERMISSION_FORUM_MODERATOR:
                editForum.setForumPermission(forumID, true);

                readPost.setForumPermission(forumID, true);
                addThread.setForumPermission(forumID, true);
                addPost.setForumPermission(forumID, true);
                editPost.setForumPermission(forumID, true);
                deletePost.setForumPermission(forumID, true);
                addPoll.setForumPermission(forumID, true);
                editPoll.setForumPermission(forumID, true);
                deletePoll.setForumPermission(forumID, true);
                addAttachment.setForumPermission(forumID, true);
                getAttachment.setForumPermission(forumID, true);
                moderateThread.setForumPermission(forumID, true);
                break;

            case PERMISSION_LIMITED_USER:
                readPost.setForumPermission(forumID, true);
                /** @todo at the 1.0.0 beta2/beta3/RC1/RC2 release, add post is disable*/
                //addPost.setForumPermission(forumID, true);
                break;

            case PERMISSION_NORMAL_USER:
                readPost.setForumPermission(forumID, true);
                addThread.setForumPermission(forumID, true);
                addPost.setForumPermission(forumID, true);
                getAttachment.setForumPermission(forumID, true);
                break;

    /**
     * Can:
     * - login, read thread and post, reply to a thread
     * - add thread, use avatar, use private message, get attachment
     * - use attachment, create poll
     */
            case PERMISSION_POWER_USER:
                readPost.setForumPermission(forumID, true);
                addThread.setForumPermission(forumID, true);
                addPost.setForumPermission(forumID, true);
                addPoll.setForumPermission(forumID, true);
                addAttachment.setForumPermission(forumID, true);
                getAttachment.setForumPermission(forumID, true);
                break;

/**************************************************************************
 * Individual Permissions that can be applied for individual forum usages,
 * (of course it can be applied to all forums), range from 2000 to 3000
 **************************************************************************/
            case PERMISSION_EDIT_FORUM:
                editForum.setForumPermission(forumID, true);
                break;
            case PERMISSION_DELETE_FORUM:
                deleteForum.setForumPermission(forumID, true);
                break;
            case PERMISSION_ASSIGN_TO_FORUM:
                assignToForum.setForumPermission(forumID, true);
                break;
            case PERMISSION_READ_POST:
                readPost.setForumPermission(forumID, true);
                break;
            case PERMISSION_ADD_THREAD:
                addThread.setForumPermission(forumID, true);
                break;
            case PERMISSION_ADD_POST:
                addPost.setForumPermission(forumID, true);
                break;
            case PERMISSION_EDIT_POST:
                editPost.setForumPermission(forumID, true);
                break;
            case PERMISSION_DELETE_POST:
                deletePost.setForumPermission(forumID, true);
                break;
            case PERMISSION_ADD_POLL:
                addPoll.setForumPermission(forumID, true);
                break;
            case PERMISSION_EDIT_POLL:
                editPoll.setForumPermission(forumID, true);
                break;
            case PERMISSION_DELETE_POLL:
                deletePoll.setForumPermission(forumID, true);
                break;
            case PERMISSION_ADD_ATTACHMENT:
                addAttachment.setForumPermission(forumID, true);
                break;
            case PERMISSION_GET_ATTACHMENT:
                getAttachment.setForumPermission(forumID, true);
                break;
            case PERMISSION_MODERATE_THREAD:
                moderateThread.setForumPermission(forumID, true);
                break;


/**************************************************************************
 * cannot find, just throw an Exception
 **************************************************************************/

            default:
                throw new AssertionException("Currently in setPermissionInForum do not support permission = " + permission);
        }//switch
    }//setPermissionInForum

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.