use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class PratilipiDocUtil method getContentImage.
public static BlobEntry getContentImage(long pratilipiId, String name, Integer width) throws InsufficientAccessException, UnexpectedServerException {
Pratilipi pratilipi = DataAccessorFactory.getDataAccessor().getPratilipi(pratilipiId);
if (!PratilipiDataUtil.hasAccessToReadPratilipiContent(pratilipi))
throw new InsufficientAccessException();
BlobEntry blobEntry = DataAccessorFactory.getBlobAccessor().getBlob("pratilipi/" + pratilipiId + "/images/" + name);
if (width != null)
blobEntry = ImageUtil.resize(blobEntry, width);
return blobEntry;
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class UserAuthorDataUtil method saveUserAuthorFollow.
public static UserAuthorData saveUserAuthorFollow(Long userId, Long authorId, UserFollowState followState) throws InvalidArgumentException, InsufficientAccessException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserAuthor userAuthor = dataAccessor.getUserAuthor(userId, authorId);
if (userAuthor == null) {
userAuthor = dataAccessor.newUserAuthor();
userAuthor.setUserId(userId);
userAuthor.setAuthorId(authorId);
}
if (!hasAccessToUpdateUserAuthorData(userAuthor, AccessType.USER_AUTHOR_FOLLOWING))
throw new InsufficientAccessException();
AccessToken accessToken = AccessTokenFilter.getAccessToken();
AuditLog auditLog = dataAccessor.newAuditLog(accessToken, AccessType.USER_AUTHOR_FOLLOWING, userAuthor);
userAuthor.setFollowState(followState);
userAuthor.setFollowDate(new Date());
userAuthor = dataAccessor.createOrUpdateUserAuthor(userAuthor, auditLog);
return createUserAuthorData(userAuthor);
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class UserDataUtil method _loginFederatedUser.
private static UserData _loginFederatedUser(UserData apiUserData, User user, UserSignUpSource signUpSource) throws InsufficientAccessException {
// Do nothing if a user is already logged in
if (!AccessTokenFilter.getAccessToken().getUserId().equals(0L))
return getCurrentUser();
// Note: Users having Facebook or Google Id can never be in GUEST or REFERRAL state.
// Note: No action required for REGISTERED or ACTIVE users.
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
boolean isNew = false;
if (user == null || user.getState() == UserState.DELETED) {
if (apiUserData.getEmail() != null)
user = dataAccessor.getUserByEmail(apiUserData.getEmail());
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), null, null);
if (user == null || user.getState() == UserState.DELETED) {
user = dataAccessor.newUser();
auditLog.setAccessType(AccessType.USER_ADD);
auditLog.setEventDataOld(user);
user.setEmail(apiUserData.getEmail());
// Counting on Facebook / Google for e-mail/user verification
user.setState(UserState.ACTIVE);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
isNew = true;
} else if (user.getState() == UserState.REFERRAL) {
auditLog.setAccessType(AccessType.USER_ADD);
auditLog.setEventDataOld(user);
// Counting on Facebook / Google for e-mail/user verification
user.setState(UserState.ACTIVE);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
isNew = true;
} else if (user.getState() == UserState.REGISTERED) {
auditLog.setAccessType(AccessType.USER_UPDATE);
auditLog.setEventDataOld(user);
// Counting on Facebook / google for e-mail/user verification
user.setState(UserState.ACTIVE);
} else {
// user.getState() == UserState.ACTIVE || user.getState() == UserState.BLOCKED
auditLog.setAccessType(AccessType.USER_UPDATE);
auditLog.setEventDataOld(user);
}
if (apiUserData.getFacebookId() != null)
user.setFacebookId(apiUserData.getFacebookId());
if (apiUserData.getGoogleId() != null)
user.setGoogleId(apiUserData.getGoogleId());
user.setLastUpdated(new Date());
user = dataAccessor.createOrUpdateUser(user, auditLog);
}
if (user.getState() == UserState.BLOCKED)
throw new InsufficientAccessException(GenericRequest.ERR_ACCOUNT_BLOCKED);
_loginUser(AccessTokenFilter.getAccessToken(), user);
UserData userData = createUserData(user);
if (isNew) {
userData.setFirstName(apiUserData.getFirstName());
userData.setLastName(apiUserData.getLastName());
userData.setGender(apiUserData.getGender());
userData.setDateOfBirth(apiUserData.getDateOfBirth());
}
return userData;
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class PratilipiDataUtil method updatePratilipiTags.
public static boolean updatePratilipiTags(long pratilipiId, PratilipiType pratilipiType, List<Long> tagIds, List<String> suggestedTags) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Pratilipi pratilipi = dataAccessor.getPratilipi(pratilipiId);
if (pratilipi == null)
return false;
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.PRATILIPI_UPDATE, pratilipi);
PratilipiData pratilipiData = createPratilipiData(pratilipi);
AccessToken accessToken = AccessTokenFilter.getAccessToken();
logger.log(Level.INFO, "User Id : " + accessToken.getUserId());
if (!hasAccessToUpdatePratilipiData(pratilipi, pratilipiData)) {
throw new InsufficientAccessException();
}
if (pratilipiType != null)
pratilipi.setType(pratilipiType);
if (tagIds != null)
pratilipi.setTagIds(tagIds);
if (suggestedTags != null)
pratilipi.setSuggestedTags(suggestedTags);
dataAccessor.createOrUpdatePratilipi(pratilipi, auditLog);
return true;
}
use of com.pratilipi.common.exception.InsufficientAccessException in project pratilipi by Pratilipi.
the class DeleteTagsApi method addTags.
@Post
public GenericResponse addTags(PostRequest request) throws InsufficientAccessException {
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (accessToken.getUserId() != 5073076857339904L) {
Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "AccessToken : " + accessToken.getId());
Logger.getLogger(TagsApi.class.getSimpleName()).log(Level.SEVERE, "User Id : " + accessToken.getUserId());
throw new InsufficientAccessException();
}
TagDataUtil.removeTags(request.getIds());
return new GenericResponse();
}
Aggregations