Skip to content

Commit

Permalink
(GH-1353) List subcommand does not need admin
Browse files Browse the repository at this point in the history
When running the list subcommand, such as `choco source list`, it
doesn't need admin privileges to provide read only information, so the
check against whether a command may require admin privileges should be
a bit smarter to see what sub-command it is about to run.
  • Loading branch information
ferventcoder committed Jul 5, 2017
1 parent d5190c0 commit 30407e5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace chocolatey.infrastructure.app.commands
using commandline;
using configuration;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using services;

Expand Down Expand Up @@ -148,7 +149,10 @@ public virtual void run(ChocolateyConfiguration configuration)

public virtual bool may_require_admin_access()
{
return true;
var config = Config.get_configuration_settings();
if (config == null) return true;

return !string.IsNullOrWhiteSpace(config.ApiKeyCommand.Key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace chocolatey.infrastructure.app.commands
using configuration;
using domain;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using services;

Expand Down Expand Up @@ -151,7 +152,10 @@ public virtual void run(ChocolateyConfiguration configuration)

public virtual bool may_require_admin_access()
{
return true;
var config = Config.get_configuration_settings();
if (config == null) return true;

return config.ConfigCommand.Command != ConfigCommandType.list;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace chocolatey.infrastructure.app.commands
using configuration;
using domain;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using services;

Expand Down Expand Up @@ -124,7 +125,10 @@ public virtual void run(ChocolateyConfiguration configuration)

public virtual bool may_require_admin_access()
{
return true;
var config = Config.get_configuration_settings();
if (config == null) return true;

return config.FeatureCommand.Command != FeatureCommandType.list;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace chocolatey.infrastructure.app.commands
using configuration;
using domain;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using nuget;
using services;
Expand Down Expand Up @@ -204,7 +205,10 @@ public virtual void set_pin(IPackageManager packageManager, ChocolateyConfigurat

public virtual bool may_require_admin_access()
{
return true;
var config = Config.get_configuration_settings();
if (config == null) return true;

return config.PinCommand.Command != PinCommandType.list;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace chocolatey.infrastructure.app.commands
using configuration;
using domain;
using infrastructure.commands;
using infrastructure.configuration;
using logging;
using services;

Expand Down Expand Up @@ -181,7 +182,10 @@ public virtual int count(ChocolateyConfiguration config)

public virtual bool may_require_admin_access()
{
return true;
var config = Config.get_configuration_settings();
if (config == null) return true;

return config.SourceCommand.Command != SourceCommandType.list;
}
}
}

0 comments on commit 30407e5

Please sign in to comment.