disable import for the demo user

This commit is contained in:
Athou
2013-05-22 12:43:36 +02:00
parent 891102a8e8
commit dd4de7c9b4
2 changed files with 10 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.commafeed.backend.StartupBean;
import com.commafeed.backend.dao.UserDAO;
import com.commafeed.backend.feeds.OPMLImporter;
import com.commafeed.backend.model.ApplicationSettings;
@@ -95,6 +96,10 @@ public class GoogleImportCallbackPage extends WebPage {
String opml = httpRequest.execute().parseAsString();
User user = CommaFeedSession.get().getUser();
if (user != null) {
if (StartupBean.USERNAME_DEMO.equals(user.getName())) {
throw new DisplayException(
"Import is disabled for the demo account");
}
importer.importOpml(CommaFeedSession.get().getUser(), opml);
}
} catch (Exception e) {

View File

@@ -28,6 +28,7 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.commafeed.backend.StartupBean;
import com.commafeed.backend.feeds.FetchedFeed;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedEntryStatus;
@@ -326,6 +327,10 @@ public class FeedREST extends AbstractResourceREST {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(value = "OPML import", notes = "Import an OPML file, posted as a FORM with the 'file' name")
public Response importOpml() {
if (StartupBean.USERNAME_DEMO.equals(getUser().getName())) {
return Response.status(Status.UNAUTHORIZED)
.entity("Import is disabled for the demo account").build();
}
try {
FileItemFactory factory = new DiskFileItemFactory(1000000, null);
ServletFileUpload upload = new ServletFileUpload(factory);