package cn.com.qmth.stmms.common.utils;

import cn.com.qmth.stmms.common.domain.WebUser;
import cn.com.qmth.stmms.common.enums.Auth;
import cn.com.qmth.stmms.common.enums.Role;

public class RoleAuthUtils {

    public static boolean hasRole(WebUser user, Role role) {
        boolean result = false;
        if (user != null && role != null && user.getRoles() != null) {
            for (Role item : user.getRoles()) {
                if (item.equals(role)) {
                    result = true;
                    break;
                }
            }
        }
        return result;
    }

    public static boolean hasAuth(WebUser user, Auth auth) {
        boolean result = false;
        if (user != null && auth != null && user.getAuthMap() != null) {
            result = user.getAuthMap().containsKey(auth.getName());
        }
        return result;
    }
}
