001/**
002 * Copyright 2011-2014 The Kuali Foundation Licensed under the Educational
003 * Community License, Version 2.0 (the "License"); you may not use this file
004 * except in compliance with the License. You may obtain a copy of the License
005 * at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software
010 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
011 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
012 * License for the specific language governing permissions and limitations under
013 * the License.
014 */
015package org.kuali.mobility.writer.entity;
016
017import org.kuali.mobility.security.authz.expression.Expression;
018import org.kuali.mobility.security.authz.expression.GroupExpression;
019import org.kuali.mobility.security.authz.expression.OrExpression;
020
021/**
022 * A class defining permission for the Library Tool
023 * @author Kuali Mobility Team (mobility.collab@kuali.org)
024 * @since 2.3.0
025 */
026public class WriterPermissions {
027
028
029        public static final String SPAMMER_PREFIX = "WRITER_SPAMMER_";
030
031    public static final String JOURNALIST_PREFIX = "WRITER_JOURNALIST_";
032
033    public static final String EDITOR_PREFIX = "WRITER_EDITOR_";
034
035    public static final String ADMIN_PREFIX = "WRITER_ADMIN_";
036
037
038    /**
039     * Builds and returns an expression that checks if the user is a spammer of a specific writer instance
040     * @param instance Instance to check against.
041     * @return The expression that can be used to check the permission.
042     */
043    public static Expression getSpammerExpression(String instance){
044        return new GroupExpression(SPAMMER_PREFIX + instance.toUpperCase());
045    }
046
047    /**
048     * Builds and returns an expression that checks if the user is a journalist of a specific writer instance
049     * @param instance Instance to check against.
050     * @return The expression that can be used to check the permission.
051     */
052    public static Expression getJournalistExpression(String instance){
053        return new GroupExpression(JOURNALIST_PREFIX + instance.toUpperCase());
054    }
055
056    /**
057     * Builds and returns an expression that checks if the user is an editor of a specific writer instance
058     * @param instance Instance to check against.
059     * @return The expression that can be used to check the permission.
060     */
061    public static Expression getEditorExpression(String instance){
062        return new GroupExpression(EDITOR_PREFIX + instance.toUpperCase());
063    }
064
065    /**
066     * Builds and returns an expression that checks if the user is an admin of a specific writer instance
067     * @param instance Instance to check against.
068     * @return The expression that can be used to check the permission.
069     */
070    public static Expression getAdminExpression(String instance){
071        return new GroupExpression(ADMIN_PREFIX + instance.toUpperCase());
072    }
073
074
075    /**
076     * Builds and returns an expression that checks if the user is a journalist or an editor of a specific writer instance
077     * @param instance Instance to check against.
078     * @return The expression that can be used to check the permission.
079     */
080    public static Expression getJournalistOrEditorExpression(String instance){
081        return new OrExpression().addChild(getJournalistExpression(instance)).addChild(getEditorExpression(instance));
082    }
083
084    /**
085     * Builds and returns an expression that checks if the user is an editor or an admin of a specific writer instance
086     * @param instance Instance to check against.
087     * @return The expression that can be used to check the permission.
088     */
089    public static Expression getEditorOrAdminExpression(String instance){
090        return new OrExpression().addChild(getEditorExpression(instance)).addChild(getAdminExpression(instance));
091    }
092
093
094}