use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method getFcmTokenList.
@Override
public List<String> getFcmTokenList(Long userId) {
if (userId == null || userId == 0L)
return null;
List<AccessTokenEntity> accessTokenList = ObjectifyService.ofy().load().type(AccessTokenEntity.class).filter("USER_ID", userId).filter("EXPIRY >", new Date()).list();
List<String> fcmTokenList = new ArrayList<>(accessTokenList.size());
for (AccessToken accessToken : accessTokenList) if (accessToken.getFcmToken() != null && !fcmTokenList.contains(accessToken.getFcmToken()))
fcmTokenList.add(accessToken.getFcmToken());
return fcmTokenList;
}
use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.
the class PratilipiDataUtil method hasAccessToListPratilipiData.
public static boolean hasAccessToListPratilipiData(PratilipiFilter pratilipiFilter) {
if (pratilipiFilter.getState() == PratilipiState.PUBLISHED)
return true;
// Case 2: User with PRATILIPI_LIST access can list Pratilipis in any State.
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (UserAccessUtil.hasUserAccess(accessToken.getUserId(), pratilipiFilter.getLanguage(), AccessType.PRATILIPI_LIST))
return true;
if (pratilipiFilter.getState() == PratilipiState.DELETED)
return false;
if (pratilipiFilter.getAuthorId() == null)
return false;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(pratilipiFilter.getAuthorId());
if (author == null)
return false;
return accessToken.getUserId().equals(author.getUserId());
}
use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.
the class AccessTokenDataUtil method setOrUpdateFcmToken.
public static void setOrUpdateFcmToken(String fcmToken) {
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (fcmToken.equals(accessToken.getFcmToken()))
return;
accessToken.setFcmToken(fcmToken);
accessToken = DataAccessorFactory.getDataAccessor().createOrUpdateAccessToken(accessToken);
}
use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.
the class PratilipiDataUtil method hasAccessToUpdatePratilipiData.
public static boolean hasAccessToUpdatePratilipiData(Pratilipi pratilipi, PratilipiData pratilipiData) {
// Case 1: Only DRAFTED/SUBMITTED/PUBLISHED content pieces can be updated.
if (pratilipi.getState() != PratilipiState.DRAFTED && pratilipi.getState() != PratilipiState.SUBMITTED && pratilipi.getState() != PratilipiState.PUBLISHED)
return false;
Author author = pratilipi.getAuthorId() == null ? null : DataAccessorFactory.getDataAccessor().getAuthor(pratilipi.getAuthorId());
// Case 2: Content pieces can be updated only if Author profile is ACTIVE.
if (author != null && author.getState() != AuthorState.ACTIVE)
return false;
// Case 3: User with PRATILIPI_UPDATE access can update any content piece.
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (UserAccessUtil.hasUserAccess(accessToken.getUserId(), pratilipi.getLanguage(), AccessType.PRATILIPI_UPDATE)) {
if (pratilipiData == null || !pratilipiData.hasLanguage() || pratilipiData.getLanguage() == pratilipi.getLanguage())
return true;
else if (UserAccessUtil.hasUserAccess(accessToken.getUserId(), pratilipiData.getLanguage(), AccessType.PRATILIPI_UPDATE))
return true;
}
// Case 4: User can update content piece linked with his/her own Author profile.
if (author != null && accessToken.getUserId().equals(author.getUserId()))
return true;
return false;
}
use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.
the class UserAuthorDataUtil method hasAccessToUpdateUserAuthorData.
public static boolean hasAccessToUpdateUserAuthorData(UserAuthor userAuthor, AccessType accessType) {
AccessToken accessToken = AccessTokenFilter.getAccessToken();
if (!userAuthor.getUserId().equals(accessToken.getUserId()))
return false;
if (!UserAccessUtil.hasUserAccess(accessToken.getUserId(), null, accessType))
return false;
// User can not follow his/her own Author profile.
if (accessType == AccessType.USER_AUTHOR_FOLLOWING) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(userAuthor.getAuthorId());
if (userAuthor.getUserId().equals(author.getUserId()))
return false;
}
return true;
}
Aggregations