Skip to content
Snippets Groups Projects
Commit cdccba56 authored by Fabiano Sluzarski's avatar Fabiano Sluzarski
Browse files

segurança adicionada

parent a6bda3c9
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.security.core.context.SecurityContextHolder;
import br.ufpr.c3sl.participatorio.enums.TipoAcao;
import br.ufpr.c3sl.participatorio.enums.TipoDemanda;
......@@ -144,4 +145,10 @@ public class Projeto {
public static List<Projeto> findAllProjetosRejeitados() {
return entityManager().createNativeQuery("SELECT * FROM Projeto WHERE estado = 'Rejeitado'", Projeto.class).getResultList();
}
public static List<Projeto> findMeusProjetos() {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
return entityManager().createNativeQuery("SELECT * FROM Projeto p, Usuario u WHERE p.usuario = u.id and p.estado = 'Candidato' and u.login = '"+login+"'", Projeto.class).getResultList();
}
}
package br.ufpr.c3sl.participatorio.web;
import br.ufpr.c3sl.participatorio.Projeto;
import br.ufpr.c3sl.participatorio.enums.TipoStatus;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
......@@ -13,6 +13,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import br.ufpr.c3sl.participatorio.Projeto;
import br.ufpr.c3sl.participatorio.Usuario;
import br.ufpr.c3sl.participatorio.enums.TipoStatus;
@RequestMapping("/projetoes")
@Controller
@RooWebScaffold(path = "projetoes", formBackingObject = Projeto.class)
......@@ -24,12 +28,32 @@ public class ProjetoController {
populateEditForm(uiModel, projeto);
return "projetoes/create";
}
uiModel.asMap().clear();
projeto.setEstado(TipoStatus.Candidato);
Usuario u = (Usuario) Usuario.entityManager().createNativeQuery("select * from usuario where login='"+SecurityContextHolder.getContext().getAuthentication().getName()+"'", Usuario.class).getSingleResult();
projeto.setUsuario(u);
uiModel.asMap().clear();
projeto.persist();
return "redirect:/projetoes/" + encodeUrlPathSegment(projeto.getId().toString(), httpServletRequest);
}
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid Projeto projeto, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, projeto);
return "projetoes/update";
}
Projeto p = (Projeto) Projeto.entityManager().createNativeQuery("select * from projeto where id = "+projeto.getId(), Projeto.class).getSingleResult();
projeto.setUsuario(p.getUsuario());
uiModel.asMap().clear();
projeto.merge();
return "redirect:/projetoes/" + encodeUrlPathSegment(projeto.getId().toString(), httpServletRequest);
}
@RequestMapping(value = "/{id}", produces = "text/html")
public String show(@PathVariable("id") Long id, Model uiModel) {
Projeto projeto = Projeto.findProjeto(id);
......@@ -85,6 +109,21 @@ public class ProjetoController {
return "projetoes/list";
}
@RequestMapping(value = "meusprojetos", produces = "text/html")
public String listMeusProjetos(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
if (page != null || size != null) {
int sizeNo = size == null ? 10 : size.intValue();
final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
uiModel.addAttribute("projetoes", Projeto.findProjetoEntries(firstResult, sizeNo));
float nrOfPages = (float) Projeto.countProjetoes() / sizeNo;
uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
} else {
uiModel.addAttribute("projetoes", Projeto.findMeusProjetos());
}
addDateTimeFormatPatterns(uiModel);
return "projetoes/list";
}
@RequestMapping(value = "/{id}", params = "status", method = RequestMethod.POST, produces = "text/html")
public String updateStatus(@PathVariable("id") Long id, @RequestParam(value = "status", required = true) String status, HttpServletRequest httpServletRequest) {
Projeto projeto = Projeto.findProjeto(id);
......
......@@ -15,11 +15,9 @@ import br.ufpr.c3sl.participatorio.web.ProjetoController;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.joda.time.format.DateTimeFormat;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -50,17 +48,6 @@ privileged aspect ProjetoController_Roo_Controller {
return "projetoes/list";
}
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String ProjetoController.update(@Valid Projeto projeto, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, projeto);
return "projetoes/update";
}
uiModel.asMap().clear();
projeto.merge();
return "redirect:/projetoes/" + encodeUrlPathSegment(projeto.getId().toString(), httpServletRequest);
}
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String ProjetoController.updateForm(@PathVariable("id") Long id, Model uiModel) {
populateEditForm(uiModel, Projeto.findProjeto(id));
......
......@@ -9,7 +9,7 @@ label_br_ufpr_c3sl_participatorio_ministerio_plural=Ministérios
label_br_ufpr_c3sl_participatorio_ministerio_version=Versão
label_br_ufpr_c3sl_participatorio_projeto=Projeto
label_br_ufpr_c3sl_participatorio_projeto_acao=Tipo de Açãoo
label_br_ufpr_c3sl_participatorio_projeto_acao=Tipo de Ação
label_br_ufpr_c3sl_participatorio_projeto_bairro=Bairro
label_br_ufpr_c3sl_participatorio_projeto_cep=Cep
label_br_ufpr_c3sl_participatorio_projeto_comofunciona=Como Funciona (Descrição da Ação)
......
......@@ -13,6 +13,8 @@ global_theme_alt=Alt
global_theme_standard=Padrão
global_generic={0}
my_projects=Meus Projetos
#welcome page
welcome_titlepane=Bem vindo ao {0}
welcome_h3=Bem vindo ao {0}
......
......@@ -9,6 +9,8 @@
<menu:item id="i_projeto_list" messageCode="global_menu_list_candidato" url="/projetoes/listCandidatos" z="user-managed"/>
<menu:item id="i_projeto_list" messageCode="global_menu_list_efetivo" url="/projetoes/listEfetivos" z="x1vvsZFRYLoITzX2jIKG93Z4DWM="/>
<menu:item id="i_projeto_list" messageCode="global_menu_list_rejeitado" url="/projetoes/listRejeitados" z="x1vvsZFRYLoITzX2jIKG93Z4DWM="/>
<menu:item id="i_projeto_list" messageCode="my_projects" url="/projetoes/meusprojetos" z="x1vvsZFRYLoITzX2jIKG93Z4DWM="/>
</menu:category>
<sec:authorize ifAnyGranted="Administrador">
......
......@@ -43,7 +43,7 @@
<field:input field="descLegislacao" id="c_br_ufpr_c3sl_participatorio_Projeto_descLegislacao" z="Y9X3/A7OHfh+T5M4c7uRjtx2Uak="/>
<field:input field="obs" id="c_br_ufpr_c3sl_participatorio_Projeto_obs" z="5b+Wjz0npE5n2wk2R6g1fJZD0VA="/>
<field:select field="estado" id="c_br_ufpr_c3sl_participatorio_Projeto_estado" items="${tipostatuses}" path="tipostatuses" render="false" z="user-managed"/>
<field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" z="4oZg5yvLrUjv5RaOV1LbaRAdauo="/>
<field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" render="false" z="user-managed"/>
</form:create>
<form:dependency dependencies="${dependencies}" id="d_br_ufpr_c3sl_participatorio_Projeto" render="${not empty dependencies}" z="nyMkb0MYQtlthVlj4JcyqCQYyRg="/>
</div>
......@@ -43,6 +43,6 @@
<field:input field="descLegislacao" id="c_br_ufpr_c3sl_participatorio_Projeto_descLegislacao" z="Y9X3/A7OHfh+T5M4c7uRjtx2Uak="/>
<field:input field="obs" id="c_br_ufpr_c3sl_participatorio_Projeto_obs" z="5b+Wjz0npE5n2wk2R6g1fJZD0VA="/>
<field:select field="estado" id="c_br_ufpr_c3sl_participatorio_Projeto_estado" items="${tipostatuses}" path="tipostatuses" z="K+kNv0Ov3Ulu6LiKPBQ71hczlOA="/>
<field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" z="4oZg5yvLrUjv5RaOV1LbaRAdauo="/>
<field:select field="usuario" id="c_br_ufpr_c3sl_participatorio_Projeto_usuario" itemValue="id" items="${usuarios}" path="/usuarios" render="false" z="user-managed"/>
</form:update>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment