Skip to content

Commit

Permalink
fix(misc): Recover application permission also when we undo delete op… (
Browse files Browse the repository at this point in the history
#916)

* fix(misc): Recover application permission also when we undo delete operation on application

* fix(misc): Fix formatting

* fix(misc): Update code comment

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
srekapalli and mergify[bot] committed Aug 5, 2020
1 parent 5ed028d commit 173b435
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Expand Up @@ -16,12 +16,16 @@

package com.netflix.spinnaker.front50.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public interface AdminOperations {
void recover(Recover operation);

@Data
@NoArgsConstructor
@AllArgsConstructor
class Recover {
String objectType;
String objectId;
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.netflix.spinnaker.front50.controllers;

import com.netflix.spinnaker.front50.model.AdminOperations;
import com.netflix.spinnaker.front50.model.ObjectType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Collection;
Expand All @@ -42,5 +43,14 @@ public AdminController(Collection<AdminOperations> adminOperations) {
@RequestMapping(value = "/recover", method = RequestMethod.POST)
void recover(@RequestBody AdminOperations.Recover operation) {
adminOperations.forEach(o -> o.recover(operation));
// Application permissions need to be recovered alongside the application itself.
if (operation.getObjectType().equalsIgnoreCase(ObjectType.APPLICATION.clazz.getSimpleName())) {
adminOperations.forEach(
o ->
o.recover(
new AdminOperations.Recover(
ObjectType.APPLICATION_PERMISSION.clazz.getSimpleName(),
operation.getObjectId())));
}
}
}
@@ -0,0 +1,49 @@
/*
* Copyright 2020 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.netflix.spinnaker.front50.controllers

import com.netflix.spinnaker.front50.model.AdminOperations
import com.netflix.spinnaker.front50.model.ObjectType
import spock.lang.Specification
import spock.lang.Subject

class AdminControllerSpec extends Specification {

AdminOperations adminOperations = Mock(AdminOperations)

@Subject
AdminController controller = new AdminController([adminOperations])


def 'should recover application and permission record'() {
given:
AdminOperations.Recover operation = new AdminOperations.Recover('application', 'test-app')

when:
controller.recover(operation)

then:
noExceptionThrown()
2 * adminOperations.recover(_) >> { AdminOperations.Recover op ->
assert op.objectId == 'test-app'
assert op.objectType.toLowerCase() in [ObjectType.APPLICATION.clazz.simpleName.toLowerCase(), ObjectType.APPLICATION_PERMISSION.clazz.simpleName.toLowerCase()]
}
0 * _
}

}

0 comments on commit 173b435

Please sign in to comment.