From 8390e075e10d9e5ea1f66b5bc5563c791549e7cc Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 12 Jun 2018 17:28:02 -0400 Subject: [PATCH] finish settings and public recordings --- app/controllers/rooms_controller.rb | 7 +-- app/controllers/users_controller.rb | 13 ++++- app/models/room.rb | 7 ++- app/models/user.rb | 7 ++- app/views/rooms/show.html.erb | 2 +- app/views/shared/_header.html.erb | 2 +- app/views/shared/_room_event.html.erb | 2 + app/views/shared/_sessions.html.erb | 4 +- .../shared/modals/_create_room_modal.html.erb | 3 +- app/views/shared/settings/_account.html.erb | 24 +++++--- app/views/shared/settings/_design.html.erb | 4 +- app/views/shared/settings/_image.html.erb | 5 -- app/views/shared/settings/_password.html.erb | 6 +- app/views/users/edit.html.erb | 58 +++++++------------ 14 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 app/views/shared/settings/_image.html.erb diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 48bd65b5..49206568 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -25,9 +25,10 @@ class RoomsController < ApplicationController # GET /r/:room_uid def show if current_user && @room.owned_by?(current_user) - @is_running = @room.is_running? @recordings = @room.recordings + @is_running = @room.is_running? else + @recordings = @room.public_recordings render :join end end @@ -97,10 +98,8 @@ class RoomsController < ApplicationController meta = { "meta_#{META_LISTED}": (params[:state] == "public") } - puts '-------------' - puts params[:record_id] + res = @room.update_recording(params[:record_id], meta) - puts res redirect_to @room if res[:updated] end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aa6f6523..d0500ee8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,6 +42,10 @@ class UsersController < ApplicationController # Update account information if passed. @user.name = user_params[:name] if user_params[:name] @user.email = user_params[:email] if user_params[:email] + @user.image = user_params[:image] if user_params[:image] + + # Custom errors not generated by validations. + errors = {} # Verify that the provided password is correct. if user_params[:password] && @user.authenticate(user_params[:password]) @@ -50,17 +54,20 @@ class UsersController < ApplicationController @user.password = user_params[:new_password] else # New passwords don't match. - + errors[:password_confirmation] = "'s don't match" end else # Original password is incorrect, can't update. - + errors[:password] = "is incorrect" end if @user.save # Notify the use that their account has been updated. redirect_to edit_user_path(@user), notice: "Information successfully updated." else + # Append custom errors. + errors.each do |k, v| @user.errors.add(k, v) end + # Handle validation errors. render :edit end @@ -82,6 +89,6 @@ class UsersController < ApplicationController end def user_params - params.require(:user).permit(:name, :email, :password, :password_confirmation, :new_password, :provider) + params.require(:user).permit(:name, :email, :image, :password, :password_confirmation, :new_password, :provider) end end diff --git a/app/models/room.rb b/app/models/room.rb index 210eea21..6a3eb413 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -109,7 +109,7 @@ class Room < ApplicationRecord end end - # Fetches all recordings for a meeting. + # Fetches all recordings for a room. def recordings res = bbb.get_recordings(meetingID: bbb_id) @@ -130,6 +130,11 @@ class Room < ApplicationRecord res[:recordings] end + # Fetches a rooms public recordings. + def public_recordings + recordings.select do |r| r[:metadata]["gl-listed"] end + end + def update_recording(record_id, meta) meta.merge!({recordID: record_id}) diff --git a/app/models/user.rb b/app/models/user.rb index 1e6c24fd..a4c5c5e2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,8 @@ class User < ApplicationRecord validates :name, length: { maximum: 24 }, presence: true validates :provider, presence: true - validates :email, length: { maximum: 60 }, allow_nil: true, + validates :image, format: {with: /\.(png|jpg)\Z/i}, allow_blank: true + validates :email, length: { maximum: 60 }, allow_blank: true, uniqueness: { case_sensitive: false }, format: {with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i } @@ -56,7 +57,7 @@ class User < ApplicationRecord end def twitter_image(auth) - auth['info']['image'] + auth['info']['image'].gsub!("_normal", "") end def google_name(auth) @@ -72,7 +73,7 @@ class User < ApplicationRecord end def google_image(auth) - auth['info']['picture'] + auth['info']['image'] end end diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb index ac1c6d6b..43f7ac78 100644 --- a/app/views/rooms/show.html.erb +++ b/app/views/rooms/show.html.erb @@ -49,7 +49,7 @@ -<%= render "shared/sessions", recordings: @recordings %> +<%= render "shared/sessions", recordings: @recordings, only_public: false %>