LCOV - code coverage report
Current view: top level - server/query/account - AccountIsVisibleToPredicate.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 8 9 88.9 %
Date: 2022-11-19 15:00:39 Functions: 3 4 75.0 %

          Line data    Source code
       1             : // Copyright (C) 2016 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.query.account;
      16             : 
      17             : import com.google.common.flogger.FluentLogger;
      18             : import com.google.gerrit.index.query.IsVisibleToPredicate;
      19             : import com.google.gerrit.server.account.AccountControl;
      20             : import com.google.gerrit.server.account.AccountState;
      21             : import com.google.gerrit.server.index.IndexUtils;
      22             : 
      23             : public class AccountIsVisibleToPredicate extends IsVisibleToPredicate<AccountState> {
      24          36 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      25             : 
      26             :   protected final AccountControl accountControl;
      27             : 
      28             :   public AccountIsVisibleToPredicate(AccountControl accountControl) {
      29          36 :     super(AccountQueryBuilder.FIELD_VISIBLETO, IndexUtils.describe(accountControl.getUser()));
      30          36 :     this.accountControl = accountControl;
      31          36 :   }
      32             : 
      33             :   @Override
      34             :   public boolean match(AccountState accountState) {
      35          32 :     boolean canSee = accountControl.canSee(accountState);
      36          32 :     if (!canSee) {
      37           1 :       logger.atFine().log("Filter out non-visisble account: %s", accountState);
      38             :     }
      39          32 :     return canSee;
      40             :   }
      41             : 
      42             :   @Override
      43             :   public int getCost() {
      44           0 :     return 1;
      45             :   }
      46             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750