Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.restapi.account; 16 : 17 : import com.google.gerrit.common.data.GlobalCapability; 18 : import com.google.gerrit.extensions.annotations.RequiresCapability; 19 : import com.google.gerrit.extensions.common.Input; 20 : import com.google.gerrit.extensions.restapi.ResourceConflictException; 21 : import com.google.gerrit.extensions.restapi.Response; 22 : import com.google.gerrit.extensions.restapi.RestApiException; 23 : import com.google.gerrit.extensions.restapi.RestModifyView; 24 : import com.google.gerrit.server.IdentifiedUser; 25 : import com.google.gerrit.server.account.AccountResource; 26 : import com.google.gerrit.server.account.SetInactiveFlag; 27 : import com.google.inject.Inject; 28 : import com.google.inject.Provider; 29 : import com.google.inject.Singleton; 30 : import java.io.IOException; 31 : import org.eclipse.jgit.errors.ConfigInvalidException; 32 : 33 : /** 34 : * REST endpoint to mark an account as inactive. 35 : * 36 : * <p>This REST endpoint handles {@code DELETE /accounts/<account-identifier>/active} requests. 37 : * 38 : * <p>Inactive accounts cannot login into Gerrit. 39 : * 40 : * <p>Marking an account as active is handled by {@link PutActive}. 41 : */ 42 : @RequiresCapability(GlobalCapability.MODIFY_ACCOUNT) 43 : @Singleton 44 : public class DeleteActive implements RestModifyView<AccountResource, Input> { 45 : 46 : private final Provider<IdentifiedUser> self; 47 : private final SetInactiveFlag setInactiveFlag; 48 : 49 : @Inject 50 148 : DeleteActive(SetInactiveFlag setInactiveFlag, Provider<IdentifiedUser> self) { 51 148 : this.setInactiveFlag = setInactiveFlag; 52 148 : this.self = self; 53 148 : } 54 : 55 : @Override 56 : public Response<?> apply(AccountResource rsrc, Input input) 57 : throws RestApiException, IOException, ConfigInvalidException { 58 8 : if (self.get().hasSameAccountId(rsrc.getUser())) { 59 2 : throw new ResourceConflictException("cannot deactivate own account"); 60 : } 61 7 : return setInactiveFlag.deactivate(rsrc.getUser().getAccountId()); 62 : } 63 : }