From 1edd26bf1b3f57da9c7753d5c23e40f476d4b4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Thu, 21 Sep 2023 14:00:00 -0300 Subject: [PATCH] add assessement endpoint --- .../components/Appbar/AppbarTabs.tsx | 18 +++++++----- app/models/assessment.rb | 23 +++++++++++++++ app/policies/assessment_policy.rb | 13 +++++++++ .../20230705145916_create_assessments.rb | 12 ++++++++ db/schema.rb | 13 ++++++++- spec/factories/assessments.rb | 28 +++++++++++++++++++ spec/models/assessment_spec.rb | 25 +++++++++++++++++ 7 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 app/models/assessment.rb create mode 100644 app/policies/assessment_policy.rb create mode 100644 db/migrate/20230705145916_create_assessments.rb create mode 100644 spec/factories/assessments.rb create mode 100644 spec/models/assessment_spec.rb diff --git a/app/javascript/components/Appbar/AppbarTabs.tsx b/app/javascript/components/Appbar/AppbarTabs.tsx index 5b0bfb0..bf06308 100644 --- a/app/javascript/components/Appbar/AppbarTabs.tsx +++ b/app/javascript/components/Appbar/AppbarTabs.tsx @@ -7,12 +7,14 @@ import { AssessmentRoutePaths, DashboardRoutePaths, QuestionRoutePaths } from ". import { RootState } from "../../services/store"; import { turnOff } from "../../services/store/unsavedChanges"; import { Dialog } from '../Dialog'; +import { useCurrentUser } from "../../contexts"; export const AppbarTabs = () => { const unsavedChanges = useSelector((state: RootState) => state.unsavedChanges) const dispatch = useDispatch() const location = useLocation() const history = useHistory() + const { isOnlyTeacher } = useCurrentUser() const [newPath, setNewPath] = useState() @@ -45,14 +47,16 @@ export const AppbarTabs = () => { tabel: 'Questões', pathname: QuestionRoutePaths.index, isCurrent: location.pathname.includes('question'), - }, - { - icon: , - tabel: 'Avaliações', - pathname: AssessmentRoutePaths.index, - isCurrent: false, + }] + + if (!isOnlyTeacher) { + links.push({ + icon: , + tabel: 'Avaliações', + pathname: AssessmentRoutePaths.index, + isCurrent: false, + }) } -] return ( <> diff --git a/app/models/assessment.rb b/app/models/assessment.rb new file mode 100644 index 0000000..e7a9c28 --- /dev/null +++ b/app/models/assessment.rb @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: assessments +# +# id :bigint not null, primary key +# observations :text +# params :jsonb +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_assessments_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +class Assessment < ApplicationRecord + belongs_to :user +end diff --git a/app/policies/assessment_policy.rb b/app/policies/assessment_policy.rb new file mode 100644 index 0000000..a37f485 --- /dev/null +++ b/app/policies/assessment_policy.rb @@ -0,0 +1,13 @@ +class AssessmentPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope.all + end + + def index? + @roles.find do |role| + admin nde coordinator center_director pro_rector teacher + end + end + end +end diff --git a/db/migrate/20230705145916_create_assessments.rb b/db/migrate/20230705145916_create_assessments.rb new file mode 100644 index 0000000..9eb689b --- /dev/null +++ b/db/migrate/20230705145916_create_assessments.rb @@ -0,0 +1,12 @@ +class CreateAssessments < ActiveRecord::Migration[7.0] + def change + create_table :assessments do |t| + t.string :title + t.text :observations + t.jsonb :params + t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fd29e44..8caa7cf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_08_05_233401) do +ActiveRecord::Schema[7.0].define(version: 2023_07_05_145916) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -56,6 +56,16 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_05_233401) do t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end + create_table "assessments", force: :cascade do |t| + t.string "title" + t.text "observations" + t.jsonb "params" + t.bigint "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_assessments_on_user_id" + end + create_table "axes", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false @@ -155,6 +165,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_05_233401) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" + add_foreign_key "assessments", "users" add_foreign_key "questions", "subjects" add_foreign_key "questions", "users" add_foreign_key "review_messages", "questions" diff --git a/spec/factories/assessments.rb b/spec/factories/assessments.rb new file mode 100644 index 0000000..1879066 --- /dev/null +++ b/spec/factories/assessments.rb @@ -0,0 +1,28 @@ +# == Schema Information +# +# Table name: assessments +# +# id :bigint not null, primary key +# observations :text +# params :jsonb +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_assessments_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +FactoryBot.define do + factory :assessment do + title { "MyString" } + observations { "MyText" } + params { "" } + user { nil } + end +end diff --git a/spec/models/assessment_spec.rb b/spec/models/assessment_spec.rb new file mode 100644 index 0000000..abcd0af --- /dev/null +++ b/spec/models/assessment_spec.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: assessments +# +# id :bigint not null, primary key +# observations :text +# params :jsonb +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_assessments_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +require 'rails_helper' + +RSpec.describe Assessment, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end