Skip to content
Snippets Groups Projects
Commit 9d09a36c authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec into rspec

parents 04c81f9a da55200a
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ class ApplicationController < ActionController::API
protected
def configure_permitted_parameters
registration_params = [:name, :email, :description, :avatar, :password, :password_confirmation, :current_password, :terms_of_service]
registration_params = [:name, :email, :description, :avatar, :cover, :password, :password_confirmation, :current_password, :terms_of_service]
devise_parameter_sanitizer.permit :sign_up, keys: registration_params
devise_parameter_sanitizer.permit :account_update, keys: registration_params
end
......
......@@ -37,12 +37,16 @@ class V1::UsersController < ApplicationController
# PUT/PATCH /v1/users/1
# PUT/PATCH /v1/users/1.json
def update
if @user.update(user_params)
user_associations(@user)
render json: @user, status: :ok
if user_params[:role_ids].blank? || current_user.is_admin?
if @user.update(user_params)
user_associations(@user)
render json: @user, status: :ok
else
render json: @user.errors, status: :unprocessable_entity
end
else
render json: @user.errors, status: :unprocessable_entity
render status: :forbidden
end
end
......@@ -106,6 +110,7 @@ class V1::UsersController < ApplicationController
:password_confirmation,
:terms_of_service,
:avatar,
:cover,
role_ids: []
)
end
......
......@@ -76,6 +76,10 @@ class User < ApplicationRecord
has_attached_file :avatar, styles: { medium: '300x300>', thumb: '60x60>' }, default_url: ''
validates_attachment_content_type :avatar, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
has_attached_file :cover, styles: { medium: '800x300>', thumb: '160x60>' }, default_url: ''
validates_attachment_content_type :cover, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
validates :terms_of_service, acceptance: true
searchkick language: 'brazilian', match: :word_start, searchable: [:name], callbacks: :async
......
......@@ -4,6 +4,10 @@ class UserPolicy < ApplicationPolicy
class Scope < PublisherPolicy::Scope; end
def update?
record if same_user? || user.is_admin?
end
def create?
user.is_admin?
end
......
......@@ -9,6 +9,6 @@ class UserSerializer < ActiveModel::Serializer
object.followed? current_user
end
attributes :id, :email, :provider, :name, :description, :education, :score, :role_ids, :institution_ids, :avatar, :likes_count, :followed, :complained, :follows_count, :learning_objects_count, :collections_count, :created_at, :updated_at
has_many :subjects
attributes :id, :email, :provider, :name, :description, :education, :score, :cover, :role_ids, :institution_ids, :avatar, :likes_count, :followed, :complained, :follows_count, :learning_objects_count, :collections_count, :created_at, :updated_at
has_many :subjects
end
class AddAttachmentCoverToUsers < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.attachment :cover
end
end
def self.down
remove_attachment :users, :cover
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment