Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.spice.profitmandi.service.user;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Who may change a partner store's status. Shared by the fofo RetailerController and the web V2FofoRetailerController
 * so the two copies of each endpoint cannot drift apart.
 */
public final class StoreAccess {

        public static final List<String> CLOSE = Collections.unmodifiableList(Arrays.asList(
                        "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com",
                        "vikas.jangra@smartdukaan.com", "neeraj.gupta@smartdukaan.com"));

        public static final List<String> DEACTIVATE = Collections.unmodifiableList(Arrays.asList(
                        "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com",
                        "vikas.jangra@smartdukaan.com"));

        public static final List<String> ACTIVATE = Collections.unmodifiableList(Arrays.asList(
                        "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "amit.gupta@smartdukaan.com"));

        public static final List<String> EXTEND_BILLING = ACTIVATE;

        private StoreAccess() {
        }

        /**
         * @param action the verb shown in the error, e.g. "close store"
         */
        public static void check(List<String> allowed, String emailId, String action) throws ProfitMandiBusinessException {
                if (emailId == null || !allowed.contains(emailId)) {
                        throw new ProfitMandiBusinessException("Access Denied", "Unauthorised Access",
                                        "You are not authorise to " + action);
                }
        }
}