Skip to content

Commit

Permalink
usuario incluye referencia a sip::persona
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara committed Apr 17, 2018
1 parent 19a7840 commit ab85c5c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ GEM
railties (>= 3.0)
builder (3.2.3)
camertron-eprun (1.1.1)
cancancan (2.1.4)
cancancan (2.2.0)
chosen-rails (1.8.3)
coffee-rails (>= 3.2)
railties (>= 3.0)
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/jn316_gen/ldap_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def crear_usuario_min(nusuario, ldapus, prob, clave)
}) if !clave.nil?
usuario.fechacreacion = Date.today
usuario.no_modificar_ldap = "1"
persona = Sip::Persona.new
usuario.nombres = persona.nombres = valor_campo_ldap(ldapus, :givenname)
usuario.apellidos = persona.apellidos = valor_campo_ldap(ldapus, :sn)
persona.sexo = 'S'
persona.save
usuario.persona_id = persona.id
usuario.save
if (usuario.errors.messages.length > 0)
prob << usuario.errors.messages.to_s
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20180409085315_rel_usuario_persona.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class RelUsuarioPersona < ActiveRecord::Migration[5.1]
def up
add_column :usuario, :persona_id, :integer
add_foreign_key :usuario, :sip_persona, column: :persona_id
execute <<-SQL
INSERT INTO sip_persona (id, nombres, apellidos, sexo)
(SELECT id, nombres, apellidos, 'S' FROM usuario);
UPDATE usuario SET persona_id=id;
SQL
end

def down
UPDATE usuario SET persona_id=NULL;
DELETE FROM sip_persona;
remove_foreign_key :usuario, :sip_persona, column: :persona_id
remove_column :usuario, :persona_id, :integer
end
end
12 changes: 11 additions & 1 deletion test/dummy/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ CREATE TABLE usuario (
apellidos character varying(50) COLLATE public.es_co_utf_8,
ultimasincldap date,
"uidNumber" integer,
persona_id integer,
CONSTRAINT usuario_check CHECK (((fechadeshabilitacion IS NULL) OR (fechadeshabilitacion >= fechacreacion))),
CONSTRAINT usuario_rol_check CHECK ((rol >= 1))
);
Expand Down Expand Up @@ -1239,6 +1240,14 @@ ALTER TABLE ONLY sip_grupo_usuario
ADD CONSTRAINT fk_rails_734ee21e62 FOREIGN KEY (usuario_id) REFERENCES usuario(id);


--
-- Name: usuario fk_rails_7947b08826; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY usuario
ADD CONSTRAINT fk_rails_7947b08826 FOREIGN KEY (persona_id) REFERENCES sip_persona(id);


--
-- Name: sip_grupo_usuario fk_rails_8d24f7c1c0; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1408,6 +1417,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20170418143627'),
('20170419010845'),
('20170419135948'),
('20180320230847');
('20180320230847'),
('20180409085315');


0 comments on commit ab85c5c

Please sign in to comment.