return buildGlobal(plugin, new Extension(plugin));
}
public UserExtension build(Plugin plugin, String userName, Iterable<Plugin> speakeasyPlugins) throws PluginOperationFailedException
{
UserExtension extension = buildGlobal(plugin, new UserExtension(plugin));
boolean canAuthor = permissionManager.canAuthorExtensions(userName);
List<String> accessList = data.getUsersList(plugin.getKey());
boolean isAuthor = userName.equals(extension.getAuthor());
boolean hasFavorited = data.getFavorites(plugin.getKey()).contains(userName);
boolean pureSpeakeasy = ExtensionValidate.isPureSpeakeasyExtension(bundleContext, plugin);
if (extension.isAvailable())
{
extension.setEnabled(accessList.contains(userName));
extension.setCanEnable(!extension.isEnabled());
extension.setCanDisable(extension.isEnabled());
}
boolean canEdit = isAuthor && pureSpeakeasy && canAuthor;
extension.setCanEdit(canEdit);
extension.setCanUninstall(canEdit);
extension.setCanFork(!extension.isFork() && pureSpeakeasy && canAuthor);
extension.setCanFavorite(!hasFavorited);
extension.setCanDownload(pureSpeakeasy && canAuthor);
// if the user has already forked this, don't let them fork again
if (!extension.isFork())
{
for (Plugin plug : speakeasyPlugins)
{
if (extension.getKey().equals(Extension.getForkedPluginKey(plug.getKey())) && userName.equals(getPluginAuthor(plug)))
{
extension.setCanFork(false);
}
}
}
// if the user is an admin and admins aren't allowed to enable
if (!permissionManager.canEnableExtensions(userName))
{
extension.setCanEnable(false);
extension.setCanFork(false);
extension.setCanEdit(false);
}
// global extensions are quite limited
final boolean isGlobalExtension = data.isGlobalExtension(plugin.getKey());
if (isGlobalExtension)
{
extension.setCanEnable(false);
extension.setCanDisable(false);
extension.setEnabled(true);
extension.setCanEdit(false);
extension.setCanUninstall(false);
extension.setCanFork(false);
}
// forks of global extensions can't be enabled
if (data.isGlobalExtension(extension.getForkedPluginKey()))
{
extension.setCanEnable(false);
}
if (userManager.isAdmin(userName))
{
// if already a global extension, allow the admin to disable it
if (isGlobalExtension)
{
extension.setCanDisableGlobally(true);
extension.setCanEdit(true);
extension.setCanUninstall(true);
}
else
{
extension.setCanEnableGlobally(true);
}
}
return extension;
}