Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up code around optional permissions #9275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2218,30 +2218,35 @@
* Returns {@code true} if the {@link Run#ARTIFACTS} permission is enabled,
* {@code false} otherwise.
*
* <p>When the {@link Run#ARTIFACTS} permission is not turned on using the
* {@code hudson.security.ArtifactsPermission} system property, this
* <p>When the {@link Run#ARTIFACTS} permission is not turned on, this
* permission must not be considered to be set to {@code false} for every
* user. It must rather be like if the permission doesn't exist at all
* (which means that every user has to have an access to the artifacts but
* the permission can't be configured in the security screen). Got it?</p>
*
* @deprecated Use {@code Run.ARTIFACTS.getEnabled()} instead.
*/
@Deprecated
public static boolean isArtifactsPermissionEnabled() {
return SystemProperties.getBoolean("hudson.security.ArtifactsPermission");
return Run.ARTIFACTS.getEnabled();
}

/**
* Returns {@code true} if the {@link Item#WIPEOUT} permission is enabled,
* {@code false} otherwise.
*
* <p>The "Wipe Out Workspace" action available on jobs is controlled by the
* {@link Item#BUILD} permission. For some specific projects, however, it is
* not acceptable to let users have this possibility, even it they can
* trigger builds. As such, when enabling the {@code hudson.security.WipeOutPermission}
* system property, a new "WipeOut" permission will allow to have greater
* control on the "Wipe Out Workspace" action.</p>
*
* @deprecated Use {@code Item.WIPEOUT.getEnabled()} instead.
*/
@Deprecated
public static boolean isWipeOutPermissionEnabled() {
return SystemProperties.getBoolean("hudson.security.WipeOutPermission");
return Item.WIPEOUT.getEnabled();

Check warning on line 2249 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 2231-2249 are not covered by tests
}

@Deprecated
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/AbstractProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@
*/
@RequirePOST
public HttpResponse doDoWipeOutWorkspace() throws IOException, ServletException, InterruptedException {
checkPermission(Functions.isWipeOutPermissionEnabled() ? WIPEOUT : BUILD);
checkPermission(Item.WIPEOUT.getEnabled() ? WIPEOUT : BUILD);

Check warning on line 1897 in core/src/main/java/hudson/model/AbstractProject.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1897 is only partially covered, one branch is missing
R b = getSomeBuildWithWorkspace();
FilePath ws = b != null ? b.getWorkspace() : null;
if (ws != null && getScm().processWorkspaceBeforeDeletion(this, ws, b.getBuiltOn())) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ default void onCreatedFromScratch() {
"WipeOut",
Messages._AbstractProject_WipeOutPermission_Description(),
null,
Functions.isWipeOutPermissionEnabled(),
SystemProperties.getBoolean("hudson.security.WipeOutPermission"),
new PermissionScope[] {PermissionScope.ITEM});
Permission CANCEL =
new Permission(
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@
* @throws AccessDeniedException Access denied
*/
public @NonNull DirectoryBrowserSupport doArtifact() {
if (Functions.isArtifactsPermissionEnabled()) {
if (ARTIFACTS.getEnabled()) {

Check warning on line 2254 in core/src/main/java/hudson/model/Run.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 2254 is only partially covered, one branch is missing
checkPermission(ARTIFACTS);
}
return new DirectoryBrowserSupport(this, getArtifactManager().root(), Messages.Run_ArtifactsBrowserTitle(project.getDisplayName(), getDisplayName()), "package.png", true);
Expand Down Expand Up @@ -2589,7 +2589,7 @@
public static final Permission UPDATE = new Permission(PERMISSIONS, "Update", Messages._Run_UpdatePermission_Description(), Permission.UPDATE, PermissionScope.RUN);
/** See {@link hudson.Functions#isArtifactsPermissionEnabled} */
public static final Permission ARTIFACTS = new Permission(PERMISSIONS, "Artifacts", Messages._Run_ArtifactsPermission_Description(), null,
Functions.isArtifactsPermissionEnabled(), new PermissionScope[]{PermissionScope.RUN});
SystemProperties.getBoolean("hudson.security.ArtifactsPermission"), new PermissionScope[]{PermissionScope.RUN});

private static class DefaultFeedAdapter implements FeedAdapter<Run> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ THE SOFTWARE.
</j:forEach>

<t:artifactList caption="${%Last Successful Artifacts}"
build="${it.lastSuccessfulBuild}" baseURL="lastSuccessfulBuild/"
permission="${it.lastSuccessfulBuild.ARTIFACTS}"/>
build="${it.lastSuccessfulBuild}" baseURL="lastSuccessfulBuild/"/>
</table>

<!-- merge fragments from the actions -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<l:task contextMenu="false" href="${url}/" icon="symbol-details" title="${%Status}"/>
<l:task href="${url}/changes" icon="symbol-changes" title="${%Changes}"/>
<l:task icon="symbol-folder" href="${url}/ws/" title="${%Workspace}" permission="${it.WORKSPACE}">
<l:task confirmationMessage="${%wipe.out.confirm}" href="${url}/doWipeOutWorkspace" icon="symbol-trash" permission="${h.isWipeOutPermissionEnabled() ? it.WIPEOUT : it.BUILD}" post="true" requiresConfirmation="true" title="${%Wipe Out Workspace}"/>
<l:task confirmationMessage="${%wipe.out.confirm}" href="${url}/doWipeOutWorkspace" icon="symbol-trash" permission="${it.WIPEOUT.getEnabled() ? it.WIPEOUT : it.BUILD}" post="true" requiresConfirmation="true" title="${%Wipe Out Workspace}"/>
</l:task>
<j:if test="${it.configurable}">
<p:configurable/>
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/resources/hudson/model/Run/artifacts-index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ THE SOFTWARE.

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:if test="${!h.isArtifactsPermissionEnabled() or h.isArtifactsPermissionEnabled() and h.hasPermission(it.ARTIFACTS)}">
<l:layout title="${it.fullDisplayName} Artifacts">
<st:include page="sidepanel.jelly" />
<l:breadcrumb title="${%Artifacts}" />
<l:main-panel>
<t:buildCaption>${%Build Artifacts}</t:buildCaption>
<table class="fileList">
<l:layout title="${it.fullDisplayName} Artifacts">
<st:include page="sidepanel.jelly" />
<l:breadcrumb title="${%Artifacts}" />
<l:main-panel>
<t:buildCaption>${%Build Artifacts}</t:buildCaption>
<table class="fileList">
<j:if test="${!h.isArtifactsPermissionEnabled() or h.isArtifactsPermissionEnabled() and h.hasPermission(it.ARTIFACTS)}">
<j:forEach var="f" items="${it.artifacts}">
<tr>
<td>
Expand All @@ -44,8 +44,8 @@ THE SOFTWARE.
</td>
</tr>
</j:forEach>
</table>
</l:main-panel>
</l:layout>
</j:if>
</j:if>
</table>
</l:main-panel>
</l:layout>
</j:jelly>
3 changes: 1 addition & 2 deletions core/src/main/resources/hudson/model/Run/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ THE SOFTWARE.
</div>

<table>
<t:artifactList build="${it}" caption="${%Build Artifacts}"
permission="${it.ARTIFACTS}" />
<t:artifactList build="${it}" caption="${%Build Artifacts}" />

<!-- give actions a chance to contribute summary item -->
<j:forEach var="a" items="${it.allActions}">
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/hudson/artifactList.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ THE SOFTWARE.
If the hyperlink to artifacts are at another URL, specify the prefix.
</st:attribute>
</st:documentation>
<j:if test="${!h.isArtifactsPermissionEnabled() or h.isArtifactsPermissionEnabled() and h.hasPermission(it,attrs.permission)}">
<j:if test="${!build.ARTIFACTS.enabled or h.hasPermission(build, build.ARTIFACTS)}">
<j:set var="artifacts" value="${build.getArtifactsUpTo(build.LIST_CUTOFF+1)}" />
<j:if test="${!empty(artifacts)}">
<t:summary icon="symbol-cube" href="${baseURL}artifact/">
Expand Down
Loading