diff --git a/.env.example b/.env.example index f4332195..ef822e0b 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,20 @@ UNSPLASH_SECRET= # Only for production SECRET_KEY_BASE= -# These two password must be identical +# value for docker-compose: postgres +DATABASE_USER= +# value for docker-compose: postgres +DATABASE_HOST= +# value for docke-compose: pek-next +DATABASE_NAME= +# DATABASE_PASSWORD= -POSTGRES_PASSWORD= + +# available values: development, staging, production +RAILS_ENV= +# enable unless RAILS_ENV is development +RAILS_SERVE_STATIC_FILES= +# provide rollbar access token for production +ROLLBAR_ACCESS_TOKEN= +# enable if used with API +NONAUTH= diff --git a/Dockerfile b/Dockerfile index 9d6d589c..37d1d34c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ WORKDIR /pek-next # Install dependencies COPY Gemfile . COPY Gemfile.lock . -RUN bundle install --deployment --without test development --retry 3 +RUN bundle install --deployment --without test --retry 3 # Copy application COPY . . diff --git a/Gemfile b/Gemfile index 69830e00..02fd2bcf 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,11 @@ gem 'activity_notification', '~> 2.2', '>= 2.2.1' gem 'pundit', '~> 2.1' gem "bootsnap", ">= 1.1.0", require: false gem 'listen' +# use jbuilder to provide data for the REST API +gem 'jbuilder', '~> 2.11', '>= 2.11.2' +# use grape to provide REST API documentation +gem 'grape' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index fe74faf0..ae70d2a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,6 +103,24 @@ GEM activemodel-serializers-xml (>= 1.0) activesupport (>= 5.0) request_store (>= 1.0) + dry-configurable (0.12.1) + concurrent-ruby (~> 1.0) + dry-core (~> 0.5, >= 0.5.0) + dry-container (0.7.2) + concurrent-ruby (~> 1.0) + dry-configurable (~> 0.1, >= 0.1.3) + dry-core (0.6.0) + concurrent-ruby (~> 1.0) + dry-inflector (0.2.0) + dry-logic (1.2.0) + concurrent-ruby (~> 1.0) + dry-core (~> 0.5, >= 0.5) + dry-types (1.5.1) + concurrent-ruby (~> 1.0) + dry-container (~> 0.3) + dry-core (~> 0.5, >= 0.5) + dry-inflector (~> 0.1, >= 0.1.2) + dry-logic (~> 1.0, >= 1.0.2) em-http-request (1.1.5) addressable (>= 2.3.4) cookiejar (!= 0.3.1) @@ -130,6 +148,13 @@ GEM ffi (1.15.0) globalid (0.4.2) activesupport (>= 4.2.0) + grape (1.5.3) + activesupport + builder + dry-types (>= 1.1) + mustermann-grape (~> 1.0.0) + rack (>= 1.3.0) + rack-accept hashie (3.6.0) http_parser.rb (0.6.0) httparty (0.17.1) @@ -137,6 +162,8 @@ GEM multi_xml (>= 0.5.2) i18n (1.8.10) concurrent-ruby (~> 1.0) + jbuilder (2.11.2) + activesupport (>= 5.0.0) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -175,6 +202,10 @@ GEM multi_json (1.12.2) multi_xml (0.6.0) multipart-post (2.1.1) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + mustermann-grape (1.0.1) + mustermann (>= 1.0.0) nio4r (2.5.7) nokogiri (1.11.2) mini_portile2 (~> 2.5.0) @@ -202,6 +233,8 @@ GEM rspec-rails (>= 3.0.0) racc (1.5.2) rack (2.2.3) + rack-accept (0.4.5) + rack (>= 0.4) rack-protection (2.0.0) rack rack-test (1.1.0) @@ -266,6 +299,7 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.2) + ruby2_keywords (0.0.4) rufus-scheduler (3.4.2) et-orbi (~> 1.0) sass (3.7.4) @@ -340,6 +374,8 @@ DEPENDENCIES em-http-request exception_handler (~> 0.8.0.0) factory_bot_rails + grape + jbuilder (~> 2.11, >= 2.11.2) jquery-rails kaminari listen diff --git a/app/api/api.rb b/app/api/api.rb new file mode 100644 index 00000000..84ebfd15 --- /dev/null +++ b/app/api/api.rb @@ -0,0 +1,5 @@ +class Api < Grape::API + prefix 'api' + format 'json' + mount Userm::Profile +end diff --git a/app/api/userm/profile.rb b/app/api/userm/profile.rb new file mode 100644 index 00000000..c473927d --- /dev/null +++ b/app/api/userm/profile.rb @@ -0,0 +1,8 @@ +module Userm + class Profile < Grape::API + get :profile do + # Your logic + 'pro' + end + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d00361d3..ab6ac758 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -73,8 +73,12 @@ def current_semester end def current_user - return impersonate_user if ENV['NONAUTH'] + if Rails.env.development? && ENV['NONAUTH'] + authorization_header = request.env["HTTP_AUTHORIZATION"] + return User.find(authorization_header.split()[1]) if authorization_header + return impersonate_user + end @current_user ||= User.includes([{ memberships: [:group] }]).find(session[:user_id]) end helper_method :current_user diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 62a9cb4d..0144462a 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -19,7 +19,10 @@ def show_by_id def show_self @user_presenter = current_user.decorate - render :show + @user = current_user + @memberships = Membership.includes(:group).where(user: current_user) + # render :show + render "show_self.json.jbuilder" end def edit; end diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index a6eff7df..d5fe6983 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -83,7 +83,7 @@ - <% if @notifications.any? %> + <% if @notifications&.any? %>