Skip to content

Commit

Permalink
Fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SofteqDG committed Dec 9, 2018
1 parent e400361 commit 7d6aa82
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 31 deletions.
Expand Up @@ -27,6 +27,7 @@
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPlugin;
import hudson.model.User;
import hudson.security.Permission;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.CheckForNull;
Expand Down Expand Up @@ -98,7 +99,7 @@ public boolean isDisplayOwnershipSummaryBox(@Nonnull TObjectType item) {

return true;
}

/**
* Gets ownership info of the requested item.
* @param item Item to be described
Expand All @@ -108,7 +109,11 @@ public boolean isDisplayOwnershipSummaryBox(@Nonnull TObjectType item) {
*/
@Nonnull
public abstract OwnershipInfo getOwnershipInfo(@Nonnull TObjectType item);


public boolean hasItemSpecificPermission(@Nonnull TObjectType item, String sid, Permission p) {
return false;
}

/**
* Gets permission required to manage ownership for the item.
* {@link Jenkins#ADMINISTER} by default if not overridden.
Expand Down
106 changes: 77 additions & 29 deletions src/main/java/org/jenkinsci/plugins/ownership/model/folders/FolderOwnershipHelper.java 100644 → 100755
Expand Up @@ -27,14 +27,17 @@
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPlugin;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPluginConfiguration;
import org.jenkinsci.plugins.ownership.security.folderspecific.FolderSpecificSecurity;
import com.synopsys.arc.jenkins.plugins.ownership.util.AbstractOwnershipHelper;
import com.synopsys.arc.jenkins.plugins.ownership.util.UserCollectionFilter;
import com.synopsys.arc.jenkins.plugins.ownership.util.userFilters.AccessRightsFilter;
import com.synopsys.arc.jenkins.plugins.ownership.util.userFilters.IUserFilter;
import com.synopsys.arc.jenkins.plugins.ownership.util.ui.OwnershipLayoutFormatter;
import hudson.Extension;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.User;
import hudson.security.Permission;
import java.io.IOException;
import java.util.Collection;
import javax.annotation.CheckForNull;
Expand All @@ -53,11 +56,19 @@
*/
public class FolderOwnershipHelper extends AbstractOwnershipHelper<AbstractFolder<?>> {

static final FolderOwnershipHelper INSTANCE = new FolderOwnershipHelper();
static final FolderOwnershipHelper Instance
= new FolderOwnershipHelper();

private static final OwnershipLayoutFormatter<AbstractFolder<?>> DEFAULT_FOLDER_FORMATTER
= new OwnershipLayoutFormatter.DefaultJobFormatter<>();

@Nonnull
public static FolderOwnershipHelper getInstance() {
return INSTANCE;
return Instance;
}

public OwnershipLayoutFormatter<AbstractFolder<?>> getLayoutFormatter() {
return DEFAULT_FOLDER_FORMATTER;
}

/**
Expand All @@ -71,38 +82,32 @@ public static FolderOwnershipProperty getOwnerProperty(@Nonnull AbstractFolder<?
return prop != null ? prop : null;
}

@Override
public String getItemTypeName(AbstractFolder<?> item) {
return "folder";
public static boolean isUserExists(@Nonnull User user) {
assert (user != null);
return isUserExists(user.getId());
}

@Override
public String getItemDisplayName(AbstractFolder<?> item) {
return item.getDisplayName();
}

@Override
public String getItemURL(AbstractFolder<?> item) {
return item.getUrl();

public static boolean isUserExists(@Nonnull String userIdOrFullName) {
return User.getById(userIdOrFullName, false) != null;
}

@Override
public OwnershipDescription getOwnershipDescription(AbstractFolder<?> item) {
// TODO: Maybe makes sense to unwrap the method to get a better performance (esp. for Security)
return getOwnershipInfo(item).getDescription();
}

@Nonnull
@Override
public Permission getRequiredPermission() {
return OwnershipPlugin.MANAGE_ITEMS_OWNERSHIP;
}

@Override
public boolean hasLocallyDefinedOwnership(@Nonnull AbstractFolder<?> folder) {
return getOwnerProperty(folder) != null;
}

@Override
public OwnershipInfo getOwnershipInfo(AbstractFolder<?> item) {
if (item == null) { // Handle renames, etc.
Expand All @@ -114,7 +119,7 @@ public OwnershipInfo getOwnershipInfo(AbstractFolder<?> item) {
if (prop != null) {
OwnershipDescription d = prop.getOwnership();
if (d.isOwnershipEnabled()) {
return new OwnershipInfo(prop.getOwnership(), new FolderOwnershipDescriptionSource(item));
return new OwnershipInfo(d, new FolderOwnershipDescriptionSource(item));
}
}

Expand All @@ -141,40 +146,83 @@ public OwnershipInfo getOwnershipInfo(AbstractFolder<?> item) {
}

@Override
public Collection<User> getPossibleOwners(AbstractFolder<?> item) {
if (OwnershipPlugin.getInstance().isRequiresConfigureRights()) {
IUserFilter filter = new AccessRightsFilter(item, AbstractFolder.CONFIGURE);
return UserCollectionFilter.filterUsers(User.getAll(), true, filter);
} else {
return User.getAll();
public boolean hasItemSpecificPermission(@Nonnull AbstractFolder<?> folder, String sid, Permission p) {
FolderOwnershipProperty prop = getOwnerProperty(folder);
if (prop != null) {
FolderSpecificSecurity sec = prop.getItemSpecificSecurity();
if (sec != null) {
return sec.getPermissionsMatrix().hasPermission(sid, p);
}
}
return false;
}

/**
* Sets the ownership information.
* @param folder Folder to be modified
* @param descr A description to be set. Use null to drop settings.
* @throws IOException
* @throws IOException
*/
public static void setOwnership(@Nonnull AbstractFolder<?> folder,
@CheckForNull OwnershipDescription descr) throws IOException {
public static void setOwnership(@Nonnull AbstractFolder<?> folder,
@CheckForNull OwnershipDescription descr) throws IOException {
FolderOwnershipProperty prop = getOwnerProperty(folder);
if (prop == null) {
prop = new FolderOwnershipProperty(descr);
prop = new FolderOwnershipProperty(descr, null);
folder.addProperty(prop);
} else {
prop.setOwnershipDescription(descr);
}
}

/**
* Sets the project-specific security.
* @param job A job to be modified
* @param security Security settings to be set. Use null to drop settings
* @throws IOException
*/
public static void setProjectSpecificSecurity(@Nonnull AbstractFolder<?> folder,
@CheckForNull FolderSpecificSecurity security) throws IOException {
FolderOwnershipProperty prop = getOwnerProperty(folder);
if (prop == null) {
throw new IOException("Ownership is not configured for "+folder);
} else {
prop.setItemSpecificSecurity(security);
}
}

@Override
public Collection<User> getPossibleOwners(AbstractFolder<?> item) {
if (OwnershipPlugin.getInstance().isRequiresConfigureRights()) {
IUserFilter filter = new AccessRightsFilter(item, AbstractFolder.CONFIGURE);
return UserCollectionFilter.filterUsers(User.getAll(), true, filter);
} else {
return User.getAll();
}
}

@Override
public String getItemTypeName(AbstractFolder<?> item) {
return "folder";
}

@Override
public String getItemDisplayName(AbstractFolder<?> item) {
return item.getDisplayName();
}

@Override
public String getItemURL(AbstractFolder<?> item) {
return item.getUrl();
}

@Extension(optional = true)
@Restricted(NoExternalUse.class)
public static class LocatorImpl extends OwnershipHelperLocator<AbstractFolder<?>> {

@Override
public AbstractOwnershipHelper<AbstractFolder<?>> findHelper(Object item) {
if (item instanceof AbstractFolder<?>) {
return INSTANCE;
return Instance;
}
return null;
}
Expand Down

0 comments on commit 7d6aa82

Please sign in to comment.