package com.atlassian.stash.internal.header.navlinks;

import com.atlassian.plugins.navlink.spi.Project;
import com.atlassian.plugins.navlink.spi.ProjectPermissionManager;
import com.atlassian.bitbucket.project.ProjectService;
import com.atlassian.bitbucket.permission.Permission;
import com.atlassian.bitbucket.permission.PermissionService;

public class NavlinksProjectPermissionManager implements ProjectPermissionManager {

    private final PermissionService permissionService;
    private final ProjectService projectService;

    public NavlinksProjectPermissionManager(PermissionService permissionService, ProjectService projectService) {
        this.permissionService = permissionService;
        this.projectService = projectService;
    }

    @Override
    public boolean canAdminister(Project project, String userName) {
        com.atlassian.bitbucket.project.Project stashProject = projectService.getByKey(project.getKey());
        return stashProject != null && permissionService.hasProjectPermission(stashProject, Permission.PROJECT_ADMIN);
    }
}
