Skip to content

Commit

Permalink
added namespace and country rights
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed May 26, 2021
1 parent 046d03e commit e614777
Show file tree
Hide file tree
Showing 17 changed files with 604 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.occurrence.Download;
import org.gbif.api.service.common.IdentityAccessService;
import org.gbif.api.vocabulary.Country;
import org.gbif.api.vocabulary.UserRole;
import org.gbif.registry.identity.model.UserModelMutationResult;

Expand Down Expand Up @@ -76,6 +77,8 @@ public interface IdentityService extends IdentityAccessService {
*/
PagingResponse<GbifUser> search(String query, @Nullable Set<UserRole> roles,
@Nullable Set<UUID> editorRightsOn,
@Nullable Set<String> namespaceRightsOn,
@Nullable Set<Country> countryRightsOn,
@Nullable Pageable page);


Expand Down Expand Up @@ -175,4 +178,34 @@ UserModelMutationResult updateEmail(
* Remove rights from the given entity for the user.
*/
void deleteEditorRight(String userName, UUID key);

/**
* Lists the namespaces the user has editor permissions on.
*/
List<String> listNamespaceRights(String userName);

/**
* Grant the user rights over the given namespace.
*/
void addNamespaceRight(String userName, String namespace);

/**
* Remove rights from the given namespace for the user.
*/
void deleteNamespaceRight(String userName, String namespace);

/**
* Lists the countries the user has editor permissions on.
*/
List<Country> listCountryRights(String userName);

/**
* Grant the user rights over the given country.
*/
void addCountryRight(String userName, Country country);

/**
* Remove rights from the given country for the user.
*/
void deleteCountryRight(String userName, Country country);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.gbif.api.model.occurrence.Download;
import org.gbif.api.model.registry.PostPersist;
import org.gbif.api.model.registry.PrePersist;
import org.gbif.api.vocabulary.Country;
import org.gbif.api.vocabulary.UserRole;
import org.gbif.registry.identity.model.ModelMutationError;
import org.gbif.registry.identity.model.PropertyConstants;
Expand Down Expand Up @@ -181,12 +182,22 @@ public GbifUser getBySystemSetting(String key, String value) {

@Override
public PagingResponse<GbifUser> list(@Nullable Pageable pageable) {
return search(null, null, null, pageable);
return search(null, null, null, null, null, pageable);
}

@Override
public PagingResponse<GbifUser> search(@Nullable String query, Set<UserRole> roles, @Nullable Set<UUID> editorRightsOn, @Nullable Pageable pageable) {
return pagingResponse(pageable, userMapper.count(query, roles, editorRightsOn), userMapper.search(query, roles, editorRightsOn, pageable));
public PagingResponse<GbifUser> search(
@Nullable String query,
Set<UserRole> roles,
@Nullable Set<UUID> editorRightsOn,
@Nullable Set<String> namespaceRightsOn,
@Nullable Set<Country> countryRightsOn,
@Nullable Pageable pageable) {
return pagingResponse(
pageable,
userMapper.count(query, roles, editorRightsOn, namespaceRightsOn, countryRightsOn),
userMapper.search(
query, roles, editorRightsOn, namespaceRightsOn, countryRightsOn, pageable));
}

/**
Expand Down Expand Up @@ -370,4 +381,34 @@ public void addEditorRight(String userName, UUID key) {
public void deleteEditorRight(String userName, UUID key) {
userMapper.deleteEditorRight(userName, key);
}

@Override
public List<String> listNamespaceRights(String userName) {
return userMapper.listNamespaceRights(userName);
}

@Override
public void addNamespaceRight(String userName, String namespace) {
userMapper.addNamespaceRight(userName, namespace);
}

@Override
public void deleteNamespaceRight(String userName, String namespace) {
userMapper.deleteNamespaceRight(userName, namespace);
}

@Override
public List<Country> listCountryRights(String userName) {
return userMapper.listCountryRights(userName);
}

@Override
public void addCountryRight(String userName, Country country) {
userMapper.addCountryRight(userName, country);
}

@Override
public void deleteCountryRight(String userName, Country country) {
userMapper.deleteCountryRight(userName, country);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private void truncateTables(DataSource dataSource) throws Exception {
* – endpoint_machine_tag
* – metasync_history
* – namespace_rights
* - country_rights
* – network_identifier
* – node_contact
* – node_endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.gbif.api.model.common.paging.Pageable;
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.occurrence.Download;
import org.gbif.api.vocabulary.Country;
import org.gbif.api.vocabulary.UserRole;
import org.gbif.registry.identity.model.UserModelMutationResult;
import org.gbif.registry.identity.service.IdentityService;
Expand Down Expand Up @@ -133,7 +134,8 @@ public PagingResponse<GbifUser> list(@Nullable Pageable pageable) {
}

@Override
public PagingResponse<GbifUser> search(String query, @Nullable Set<UserRole> roles, @Nullable Set<UUID> editorRightsOn, @Nullable Pageable page) {
public PagingResponse<GbifUser> search(String query, @Nullable Set<UserRole> roles, @Nullable Set<UUID> editorRightsOn, Set<String> namespaceRightsOn,
@Nullable Set<Country> countryRightsOn, @Nullable Pageable page) {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -209,6 +211,36 @@ public void deleteEditorRight(String userName, UUID key) {
throw new UnsupportedOperationException();
}

@Override
public List<String> listNamespaceRights(String userName) {
throw new UnsupportedOperationException();
}

@Override
public void addNamespaceRight(String userName, String namespace) {
throw new UnsupportedOperationException();
}

@Override
public void deleteNamespaceRight(String userName, String namespace) {
throw new UnsupportedOperationException();
}

@Override
public List<Country> listCountryRights(String userName) {
throw new UnsupportedOperationException();
}

@Override
public void addCountryRight(String userName, Country country) {
throw new UnsupportedOperationException();
}

@Override
public void deleteCountryRight(String userName, Country country) {
throw new UnsupportedOperationException();
}

/**
* Return a copy of the user with the lastLogin date set to now.
*
Expand Down
Loading

0 comments on commit e614777

Please sign in to comment.