Skip to content

Commit

Permalink
Land #97, Mdm::Vuln#note_id
Browse files Browse the repository at this point in the history
MSP-11994
  • Loading branch information
limhoff-r7 committed Feb 19, 2015
2 parents bdc7777 + 417c626 commit b23b774
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/models/mdm/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class Mdm::Note < ActiveRecord::Base
class_name: 'Mdm::Service',
inverse_of: :notes

# @!attribute [rw] vuln
# The vuln to which this note is attached.
#
# @return [Mdm::Vuln] if note is attached to an {Mdm::Vuln}.
# @return [nil] if not is attached to an {Mdm::Host}.
belongs_to :vuln,
class_name: 'Mdm::Vuln',
inverse_of: :notes

# @!attribute [rw] workspace
# The workspace in which the {#host} or {#service} exists.
#
Expand Down
10 changes: 10 additions & 0 deletions app/models/mdm/vuln.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class Mdm::Vuln < ActiveRecord::Base
dependent: :destroy,
inverse_of: :vuln

# @!attribute [rw] notes
# Notes about the vuln entered by a user with {Mdm::Note#created_at oldest notes} first.
#
# @return [Array<Mdm::Note>]
has_many :notes,
class_name: 'Mdm::Note',
inverse_of: :vuln,
dependent: :delete_all,
order: 'notes.created_at'

#
# Through :vuln_refs
#
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20150209195939_add_vuln_id_to_note.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddVulnIdToNote < ActiveRecord::Migration
def change
add_column :notes, :vuln_id, :integer
add_index :notes, :vuln_id
end
end
4 changes: 2 additions & 2 deletions lib/metasploit_data_models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Version
MAJOR = 0
# The minor version number, scoped to the {MAJOR} version number.
MINOR = 23
# The patch number, scoped to the {MINOR} version number.
PATCH = 0
# The patch number, scoped to the {MAJOR} and {MINOR} version numbers.
PATCH = 1

# The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the `PRERELEASE` in the
# {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
Expand Down
2 changes: 2 additions & 0 deletions spec/app/models/mdm/note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
it { should have_db_column(:workspace_id).of_type(:integer).with_options(:null => false, :default =>1) }
it { should have_db_column(:host_id).of_type(:integer) }
it { should have_db_column(:service_id).of_type(:integer) }
it { should have_db_column(:vuln_id).of_type(:integer) }
it { should have_db_column(:ntype).of_type(:string) }
it { should have_db_column(:critical).of_type(:boolean) }
it { should have_db_column(:seen).of_type(:boolean) }
Expand All @@ -44,6 +45,7 @@
it { should belong_to(:workspace).class_name('Mdm::Workspace') }
it { should belong_to(:host).class_name('Mdm::Host') }
it { should belong_to(:service).class_name('Mdm::Service') }
it { should belong_to(:vuln).class_name('Mdm::Vuln') }
end

context 'scopes' do
Expand Down
1 change: 1 addition & 0 deletions spec/app/models/mdm/vuln_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
it { should have_many(:vuln_details).class_name('Mdm::VulnDetail').dependent(:destroy) }
# @todo https://www.pivotaltracker.com/story/show/49004623
it { should have_many(:vulns_refs).class_name('Mdm::VulnRef').dependent(:destroy) }
it { should have_many(:notes).class_name('Mdm::Note').dependent(:delete_all).order('notes.created_at') }

context 'module_details' do
it { should have_many(:module_details).class_name('Mdm::Module::Detail').through(:module_refs) }
Expand Down
12 changes: 11 additions & 1 deletion spec/dummy/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ CREATE TABLE notes (
updated_at timestamp without time zone,
critical boolean,
seen boolean,
data text
data text,
vuln_id integer
);


Expand Down Expand Up @@ -2679,6 +2680,13 @@ CREATE INDEX index_module_targets_on_module_detail_id ON module_targets USING bt
CREATE INDEX index_notes_on_ntype ON notes USING btree (ntype);


--
-- Name: index_notes_on_vuln_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--

CREATE INDEX index_notes_on_vuln_id ON notes USING btree (vuln_id);


--
-- Name: index_refs_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
Expand Down Expand Up @@ -2998,6 +3006,8 @@ INSERT INTO schema_migrations (version) VALUES ('20150112203945');

INSERT INTO schema_migrations (version) VALUES ('20150205192745');

INSERT INTO schema_migrations (version) VALUES ('20150209195939');

INSERT INTO schema_migrations (version) VALUES ('20150212214222');

INSERT INTO schema_migrations (version) VALUES ('21');
Expand Down

0 comments on commit b23b774

Please sign in to comment.