Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer tokens #206

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.apidb.apicommon.controller;

import java.util.Map;

import org.apidb.apicommon.model.comment.CommentFactory;
import org.apidb.apicommon.model.comment.pojo.Author;
import org.gusdb.fgputil.accountdb.UserProfile;
import org.gusdb.fgputil.events.Event;
import org.gusdb.fgputil.events.Events;
import org.gusdb.oauth2.client.veupathdb.User;
import org.gusdb.oauth2.client.veupathdb.UserProperty;
import org.gusdb.wdk.events.UserProfileUpdateEvent;
import org.gusdb.wdk.model.WdkModel;
import org.gusdb.wdk.model.WdkModelException;
Expand Down Expand Up @@ -36,13 +35,11 @@ private static void userProfileUpdateListener(Event event)
UserProfileUpdateEvent updateEvent = (UserProfileUpdateEvent) event;

// check to see if any of the property text fields changed
Map<String, String> userProps = updateEvent.getNewProfile().getProperties();
Map<String, String> oldProfileProps = updateEvent.getOldProfile()
.getProperties();
boolean commentSearchTextUpdateRequired = false;

for (String key : oldProfileProps.keySet()) {
if (!oldProfileProps.get(key).equals(userProps.get(key))) {
String[] commentProps = new String[] { "firstName", "lastName", "organization" };
for (String key : commentProps) {
UserProperty prop = User.USER_PROPERTIES.get(key);
if (!prop.getValue(updateEvent.getOldUser()).equals(prop.getValue(updateEvent.getNewUser()))) {
commentSearchTextUpdateRequired = true;
}
}
Expand All @@ -54,12 +51,12 @@ private static void userProfileUpdateListener(Event event)
// need to write updated text to comment search field
CommentFactory commentFactory = CommentFactoryManager.getCommentFactory(
updateEvent.getWdkModel().getProjectId());
UserProfile profile = updateEvent.getNewProfile();
User user = updateEvent.getNewUser();

commentFactory.updateAuthor(new Author()
.setFirstName(profile.getProperties().get("firstName"))
.setLastName(profile.getProperties().get("lastName"))
.setOrganization(profile.getProperties().get("organization"))
.setUserId(profile.getUserId()));
.setFirstName(user.getFirstName())
.setLastName(user.getLastName())
.setOrganization(user.getOrganization())
.setUserId(user.getUserId()));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.apidb.apicommon.model.comment;

import java.util.Collection;
import java.util.stream.Collectors;

import org.apidb.apicommon.model.comment.pojo.CommentRequest;
import org.apidb.apicommon.model.comment.pojo.ExternalDatabase;
import org.gusdb.fgputil.FormatUtil;
import org.gusdb.wdk.model.WdkModel;
import org.gusdb.wdk.model.user.User;

import java.util.Collection;
import java.util.stream.Collectors;

public class CommentAlertEmailFormatter {
private static final String
FIELD_COMMENT_ID = "Comment Id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,66 @@
package org.apidb.apicommon.model.comment;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apidb.apicommon.model.comment.pojo.*;
import org.apidb.apicommon.model.comment.repo.*;
import org.gusdb.fgputil.db.pool.DatabaseInstance;
import org.gusdb.fgputil.runtime.InstanceManager;
import org.gusdb.fgputil.runtime.Manageable;
import org.gusdb.wdk.model.WdkModel;
import org.gusdb.wdk.model.WdkModelException;
import org.gusdb.wdk.model.config.ModelConfigUserDB;
import org.gusdb.wdk.model.user.User;
import static org.apidb.apicommon.model.comment.ReferenceType.ACCESSION;
import static org.apidb.apicommon.model.comment.ReferenceType.AUTHOR;
import static org.apidb.apicommon.model.comment.ReferenceType.DIGITAL_OBJECT_ID;
import static org.apidb.apicommon.model.comment.ReferenceType.PUB_MED;

import javax.sql.DataSource;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import javax.sql.DataSource;

import org.apidb.apicommon.model.comment.pojo.Attachment;
import org.apidb.apicommon.model.comment.pojo.Author;
import org.apidb.apicommon.model.comment.pojo.Category;
import org.apidb.apicommon.model.comment.pojo.Comment;
import org.apidb.apicommon.model.comment.pojo.CommentRequest;
import org.apidb.apicommon.model.comment.pojo.ExternalDatabase;
import org.apidb.apicommon.model.comment.pojo.Project;
import org.apidb.apicommon.model.comment.pojo.PubMedReference;
import org.apidb.apicommon.model.comment.repo.DeleteAttachmentQuery;
import org.apidb.apicommon.model.comment.repo.FindCommentQuery;
import org.apidb.apicommon.model.comment.repo.GetAllAttachmentsQuery;
import org.apidb.apicommon.model.comment.repo.GetAttachmentQuery;
import org.apidb.apicommon.model.comment.repo.GetAuthorQuery;
import org.apidb.apicommon.model.comment.repo.GetCategoriesQuery;
import org.apidb.apicommon.model.comment.repo.GetCommentExistsQuery;
import org.apidb.apicommon.model.comment.repo.GetCommentQuery;
import org.apidb.apicommon.model.comment.repo.GetExternalDatabaseQuery;
import org.apidb.apicommon.model.comment.repo.HideCommentQuery;
import org.apidb.apicommon.model.comment.repo.InsertAttachmentQuery;
import org.apidb.apicommon.model.comment.repo.InsertAuthorQuery;
import org.apidb.apicommon.model.comment.repo.InsertCategoryQuery;
import org.apidb.apicommon.model.comment.repo.InsertCommentQuery;
import org.apidb.apicommon.model.comment.repo.InsertExternalDatabaseLinkQuery;
import org.apidb.apicommon.model.comment.repo.InsertExternalDatabaseQuery;
import org.apidb.apicommon.model.comment.repo.InsertLocationQuery;
import org.apidb.apicommon.model.comment.repo.InsertReferencesQuery;
import org.apidb.apicommon.model.comment.repo.InsertSequenceQuery;
import org.apidb.apicommon.model.comment.repo.InsertStableIdQuery;
import org.apidb.apicommon.model.comment.repo.Table;
import org.apidb.apicommon.model.comment.repo.UpdateAttachmentQuery;
import org.apidb.apicommon.model.comment.repo.UpdateAuthorQuery;
import org.eupathdb.sitesearch.data.comments.UserCommentUpdater;
import org.gusdb.fgputil.db.pool.DatabaseInstance;
import org.gusdb.fgputil.runtime.InstanceManager;
import org.gusdb.fgputil.runtime.Manageable;
import org.gusdb.wdk.model.WdkModel;
import org.gusdb.wdk.model.WdkModelException;
import org.gusdb.wdk.model.config.ModelConfigUserDB;
import org.gusdb.wdk.model.user.User;

import static org.apidb.apicommon.model.comment.ReferenceType.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* Manages user comments on WDK records
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import org.gusdb.wdk.model.user.User;

import java.util.Map;

public class Author {

private String _firstName;

private String _lastName;
Expand Down Expand Up @@ -50,11 +49,10 @@ public Author setUserId(long userId) {
}

public static Author fromUser(final User user) {
final Map<String, String> props = user.getProfileProperties();
return new Author()
.setUserId(user.getUserId())
.setFirstName(props.get("firstName"))
.setLastName(props.get("lastName"))
.setOrganization(props.get("organization"));
.setFirstName(user.getFirstName())
.setLastName(user.getLastName())
.setOrganization(user.getOrganization());
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.apidb.apicommon.model.comment.repo;

import static java.sql.Types.BIGINT;
import static java.sql.Types.CLOB;
import static java.sql.Types.VARCHAR;

import java.io.StringReader;

import org.apidb.apicommon.model.comment.ReviewStatus;
import org.apidb.apicommon.model.comment.pojo.CommentRequest;
import org.apidb.apicommon.model.comment.pojo.Project;
import org.gusdb.fgputil.db.runner.BasicArgumentBatch;
import org.gusdb.fgputil.db.runner.SQLRunner;
import org.gusdb.wdk.model.user.User;

import java.io.StringReader;

import static java.sql.Types.*;

/**
* Insert a new comment record.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.gusdb.wdk.model.record.attribute.AttributeField;
import org.gusdb.wdk.model.record.attribute.AttributeValue;
import org.gusdb.wdk.model.user.Step;
import org.gusdb.wdk.model.user.UnregisteredUser.UnregisteredUserType;
import org.gusdb.wdk.model.user.User;
import org.gusdb.wdk.model.user.UserCache;
import org.json.JSONObject;
Expand Down Expand Up @@ -105,7 +104,7 @@ public static void main(String[] args) throws Exception {
/*%%%%%%%%%%%%%%%%%%%%%%%%%%% helper functions %%%%%%%%%%%%%%%%%%%%%%%%%%%*/

private static RunnableObj<Step> createStep(WdkModel model) throws WdkModelException {
User user = model.getUserFactory().createUnregistedUser(UnregisteredUserType.GUEST);
User user = model.getSystemUser();
return Step.builder(model, user.getUserId(), model.getStepFactory().getNewStepId())
.setAnswerSpec(AnswerSpec.builder(model)
.setQuestionFullName(QUESTION_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected RevisedRequest<BasketActions> translatePatchRequest(
return new RevisedRequest<>(
getTranscriptRecordClass(getWdkModel()),
new BasketActions(actions.getAction(), Collections.emptyList())
.setRunnableAnswerSpec(newSpec.buildRunnable(getSessionUser(), step.get().getContainer())));
.setRunnableAnswerSpec(newSpec.buildRunnable(getRequestingUser(), step.get().getContainer())));
}

// translate IDs to gene PKs if necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected JSONObject addSupplementalProjectInfo(JSONObject projectJson) throws W
// get all organisms in vocabulary of org param of taxon question
Question taxonQuestion = model.getQuestionByName(TAXON_QUESTION_NAME).get();
DisplayablyValid<AnswerSpec> spec = QuestionService.getDisplayableAnswerSpec(
TAXON_QUESTION_NAME, model, getSessionUser(), name -> taxonQuestion);
TAXON_QUESTION_NAME, model, getRequestingUser(), name -> taxonQuestion);
AbstractEnumParam orgParam = (AbstractEnumParam)taxonQuestion.getParamMap().get(ORGANISM_PARAM_NAME);
List<String> organisms = orgParam.getVocabInstance(AnswerSpec.getValidQueryInstanceSpec(spec)).getVocabTreeLeafTerms();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private String resolveOrganism(String recordClassUrlSegment, String primaryKeyVa
throw new BadRequestException("Record type with url segment '" + recordClassUrlSegment + "' does not contain an '" + ORGANISM_ATTRIBUTE + "' attribute.");
}
PrimaryKeyValue pkValue = getPkValue(recordClass, primaryKeyValues);
List<RecordInstance> records = RecordClass.getRecordInstances(getSessionUser(), pkValue);
List<RecordInstance> records = RecordClass.getRecordInstances(getRequestingUser(), pkValue);
if (records.isEmpty()) {
throw new BadRequestException("Primary Key '" + primaryKeyValues + "' does not map to any records of type '" + recordClassUrlSegment + "'.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void setTranscriptFlag(@PathParam("stepId") Integer stepId, String body)
LOG.info("Action is to turn filter: " + filterTurnedOn);

Step step = getWdkModel().getStepFactory().getStepByIdAndUserId(
stepId, getSessionUser().getUserId(), ValidationLevel.SYNTACTIC)
stepId, getRequestingUser().getUserId(), ValidationLevel.SYNTACTIC)
.orElseThrow(() -> new NotFoundException("No step exists with ID " + stepId));

AnswerSpecBuilder newSpec = AnswerSpec.builder(step.getAnswerSpec());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package org.apidb.apicommon.service.services.comments;

import java.util.function.Supplier;

import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.NotFoundException;

import org.apidb.apicommon.controller.CommentFactoryManager;
import org.apidb.apicommon.model.comment.CommentFactory;
import org.apidb.apicommon.model.comment.pojo.Comment;
import org.gusdb.wdk.model.WdkModelException;
import org.gusdb.wdk.model.user.User;
import org.gusdb.wdk.service.service.AbstractWdkService;

import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.NotFoundException;
import java.util.function.Supplier;

public abstract class AbstractUserCommentService extends AbstractWdkService {
protected CommentFactory getCommentFactory() {
return CommentFactoryManager.getCommentFactory(getWdkModel().getProjectId());
}

protected User fetchUser() {
final User out = getSessionUser();
final User out = getRequestingUser();
if (out.isGuest())
throw new NotAuthorizedException("you must login before performing this action");
return out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public JSONObject getAllUserDatasetsJBrowse(@PathParam("organism") String public
catch (Exception e) {
tracks = new JSONArray();
Exception e2 = new WdkModelException("Unable to load JBrowse user datasets for user with ID " +
getSessionUser().getUserId() + ", organism " + publicOrganismAbbrev, e);
getRequestingUser().getUserId() + ", organism " + publicOrganismAbbrev, e);
LOG.error("Could not load JBrowse user datasets", e2);
Events.trigger(new ErrorEvent(new ServerErrorBundle(e2), getErrorContext(ErrorLocation.WDK_SERVICE)));
}
Expand Down