Skip to content

Commit

Permalink
Introduce isTableOwner method for readability
Browse files Browse the repository at this point in the history
Extracted-From: prestodb/presto#10904
  • Loading branch information
Andrii Rosa authored and sopel39 committed Jan 29, 2019
1 parent e5f2784 commit a20e9af
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ public void checkCanCreateTable(ConnectorTransactionHandle transaction, Connecto
@Override
public void checkCanDropTable(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName)
{
if (!checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (!isTableOwner(transaction, identity, tableName)) {
denyDropTable(tableName.toString());
}
}

@Override
public void checkCanRenameTable(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName, SchemaTableName newTableName)
{
if (!checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (!isTableOwner(transaction, identity, tableName)) {
denyRenameTable(tableName.toString(), newTableName.toString());
}
}
Expand All @@ -164,23 +164,23 @@ public Set<SchemaTableName> filterTables(ConnectorTransactionHandle transactionH
@Override
public void checkCanAddColumn(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName)
{
if (!checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (!isTableOwner(transaction, identity, tableName)) {
denyAddColumn(tableName.toString());
}
}

@Override
public void checkCanDropColumn(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName)
{
if (!checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (!isTableOwner(transaction, identity, tableName)) {
denyDropColumn(tableName.toString());
}
}

@Override
public void checkCanRenameColumn(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName)
{
if (!checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (!isTableOwner(transaction, identity, tableName)) {
denyRenameColumn(tableName.toString());
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public void checkCanCreateView(ConnectorTransactionHandle transaction, Connector
@Override
public void checkCanDropView(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName viewName)
{
if (!checkTablePermission(transaction, identity, viewName, OWNERSHIP)) {
if (!isTableOwner(transaction, identity, viewName)) {
denyDropView(viewName.toString());
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public void checkCanSetCatalogSessionProperty(ConnectorTransactionHandle transac
@Override
public void checkCanGrantTablePrivilege(ConnectorTransactionHandle transaction, ConnectorIdentity identity, Privilege privilege, SchemaTableName tableName, PrestoPrincipal grantee, boolean withGrantOption)
{
if (checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (isTableOwner(transaction, identity, tableName)) {
return;
}

Expand All @@ -261,7 +261,7 @@ public void checkCanGrantTablePrivilege(ConnectorTransactionHandle transaction,
@Override
public void checkCanRevokeTablePrivilege(ConnectorTransactionHandle transaction, ConnectorIdentity identity, Privilege privilege, SchemaTableName tableName, PrestoPrincipal revokee, boolean grantOptionFor)
{
if (checkTablePermission(transaction, identity, tableName, OWNERSHIP)) {
if (isTableOwner(transaction, identity, tableName)) {
return;
}

Expand Down Expand Up @@ -376,6 +376,11 @@ private boolean isDatabaseOwner(ConnectorTransactionHandle transaction, Connecto
return false;
}

private boolean isTableOwner(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName)
{
return checkTablePermission(transaction, identity, tableName, OWNERSHIP);
}

private boolean checkTablePermission(ConnectorTransactionHandle transaction, ConnectorIdentity identity, SchemaTableName tableName, HivePrivilege... requiredPrivileges)
{
if (isAdmin(transaction, identity)) {
Expand Down

0 comments on commit a20e9af

Please sign in to comment.