package com.atlassian.bitbucket.web.conditions;

import com.atlassian.bitbucket.user.ApplicationUser;
import com.atlassian.bitbucket.permission.PermissionService;

import java.util.Map;

/**
 * Verifies that the current user has a global permission
 *
 * <code>
 * <pre>
 * &lt;condition class="com.atlassian.bitbucket.web.conditions.HasGlobalPermissionCondition">
 *     &lt;param name="permission">ADMIN&lt;/param>
 * &lt;/condition>
 * </pre>
 * </code>
 */
public class HasGlobalPermissionCondition extends AbstractPermissionCondition {

    public HasGlobalPermissionCondition(PermissionService permissionService) {
        super(permissionService, true);
    }

    @Override
    protected boolean hasPermission(Map<String, Object> context) {
        return permissionService.hasGlobalPermission(getPermission());
    }

    @Override
    protected boolean hasPermission(Map<String, Object> context, ApplicationUser user) {
        return permissionService.hasGlobalPermission(user, getPermission());
    }

    @Override
    protected boolean hasPermission(Map<String, Object> context, String userName) {
        return permissionService.hasGlobalPermission(userName, getPermission());
    }
}
