fix profile generation
This commit is contained in:
@ -12,7 +12,9 @@ class ProfilesController < ApplicationController
|
|||||||
|
|
||||||
# GET /profiles/new
|
# GET /profiles/new
|
||||||
def new
|
def new
|
||||||
@profile = Profile.new
|
kind = params[:kind]
|
||||||
|
kind = Profile.types.first unless Profile.types.include?(kind)
|
||||||
|
@profile = Profile.new kind: kind
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /profiles/1/edit
|
# GET /profiles/1/edit
|
||||||
@ -26,7 +28,7 @@ class ProfilesController < ApplicationController
|
|||||||
@profile.member = current_member
|
@profile.member = current_member
|
||||||
|
|
||||||
if @profile.save
|
if @profile.save
|
||||||
redirect_to @profile, notice: "Successfully created Profile profile"
|
redirect_to member_path(current_member), notice: "Successfully created #{@profile.Kind} profile"
|
||||||
else
|
else
|
||||||
render :new, status: :unprocessable_entity
|
render :new, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
@ -36,7 +38,7 @@ class ProfilesController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
authorize @profile
|
authorize @profile
|
||||||
if @profile.update(profile_params)
|
if @profile.update(profile_params)
|
||||||
redirect_to @profile, notice: "Profile Profile was updated."
|
redirect_to member_path(current_member), notice: "#{@profile.Kind} profile was updated."
|
||||||
else
|
else
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
@ -46,7 +48,7 @@ class ProfilesController < ApplicationController
|
|||||||
def destroy
|
def destroy
|
||||||
authorize @profile
|
authorize @profile
|
||||||
@profile.destroy
|
@profile.destroy
|
||||||
redirect_to profiles_url, notice: "Profile was successfully destroyed."
|
redirect_to member_path(current_member), notice: "#{@profile.Kind} profile was successfully destroyed."
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -57,6 +59,6 @@ class ProfilesController < ApplicationController
|
|||||||
|
|
||||||
# Only allow a list of trusted parameters through.
|
# Only allow a list of trusted parameters through.
|
||||||
def profile_params
|
def profile_params
|
||||||
params.require(:profile).permit(:name, :bio, :picture)
|
params.require(:profile).permit(:name, :bio, :picture, :kind)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,16 @@ class Member < ApplicationRecord
|
|||||||
mount_uploader :picture, PictureUploader
|
mount_uploader :picture, PictureUploader
|
||||||
|
|
||||||
has_many :entities
|
has_many :entities
|
||||||
has_one :profile
|
has_many :profiles
|
||||||
|
|
||||||
|
Profile.types.each do |kind|
|
||||||
|
define_method :kind do
|
||||||
|
Profile.where( member_id: self.id).where(kind: kind).first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def profile( kind )
|
||||||
|
Profile.where( member_id: self.id).where(kind: kind).first
|
||||||
|
end
|
||||||
|
|
||||||
def admin?
|
def admin?
|
||||||
email == "torsten@villataika.fi"
|
email == "torsten@villataika.fi"
|
||||||
|
@ -8,4 +8,11 @@ class Profile < ApplicationRecord
|
|||||||
|
|
||||||
mount_uploader :picture, PictureUploader
|
mount_uploader :picture, PictureUploader
|
||||||
|
|
||||||
|
def self.types
|
||||||
|
["member" , "artist" , "teacher"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def Kind
|
||||||
|
self.kind.capitalize
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
10
app/policies/edit_own_policy.rb
Normal file
10
app/policies/edit_own_policy.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# allows to edit/detroy own data
|
||||||
|
# which can be viewed by anyone
|
||||||
|
class EditOwnPolicy < ApplicationPolicy
|
||||||
|
def edit?
|
||||||
|
(member == record.member) or member.admin?
|
||||||
|
end
|
||||||
|
alias :update? :edit?
|
||||||
|
alias :destroy? :edit?
|
||||||
|
|
||||||
|
end
|
6
app/policies/member_policy.rb
Normal file
6
app/policies/member_policy.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class MemberPolicy < EditOwnPolicy
|
||||||
|
|
||||||
|
|
||||||
|
class Scope < Scope
|
||||||
|
end
|
||||||
|
end
|
@ -1,9 +1,4 @@
|
|||||||
class ProfilePolicy < ApplicationPolicy
|
class ProfilePolicy < EditOwnPolicy
|
||||||
|
|
||||||
def edit?
|
|
||||||
(member == record.member) or member.admin?
|
|
||||||
end
|
|
||||||
alias :update? :edit?
|
|
||||||
alias :destroy? :edit?
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => "/forum", :role => "menuitem"}
|
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => "/forum", :role => "menuitem"}
|
||||||
Forum
|
Forum
|
||||||
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => main_app.member_path(current_member), :role => "menuitem"}
|
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => main_app.member_path(current_member), :role => "menuitem"}
|
||||||
Profile
|
Settings
|
||||||
- unless Rails.env.production?
|
- unless Rails.env.production?
|
||||||
- if current_member.admin?
|
- if current_member.admin?
|
||||||
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => merged.pages_path(), :role => "menuitem"}
|
%a.block.rounded-lg.px-4.py-2.text-sm.text-gray-500.hover:bg-gray-50.hover:text-gray-700{:href => merged.pages_path(), :role => "menuitem"}
|
||||||
|
@ -1,42 +1,41 @@
|
|||||||
.px-4.py-16.mx-auto.sm:max-w-xl.md:max-w-full.lg:max-w-screen-xl.md:px-24.lg:px-8.lg:py-20
|
%section.mx-20
|
||||||
.flex.flex-col.max-w-screen-lg.overflow-hidden.bg-white.border.rounded.shadow-sm.lg:flex-row.sm:mx-auto
|
.flex.justify-center
|
||||||
.relative{:class => "lg:w-1/2"}
|
.px-4.py-4.md:py-10.lg:py-16.mx-5.md:mx-12.lg:mx-20.text-center
|
||||||
-if @member.picture_url
|
%h1.text-2xl.font-bold.tracking-tight.sm:text-4xl
|
||||||
= image_tag @member.picture_url, class: "object-cover w-full lg:absolute h-80 lg:h-full"
|
Settings and profiles
|
||||||
.flex.flex-col.justify-center.p-8.lg:p-16.lg:pl-10{:class => "lg:w-1/2"}
|
%h4.text-xl.mt-4.md:text-2xl
|
||||||
|
Allowing you to create and edit various profiles
|
||||||
|
.mt-4.text-lg.pt-4
|
||||||
|
You can have seperate profiles as teacher, artist, or coop member.
|
||||||
|
If you choose to create them they will be publicly listed.
|
||||||
|
Techers and Artists may then create events.
|
||||||
|
|
||||||
|
.grid.grid-cols-2.mx-20
|
||||||
|
.first
|
||||||
|
- Profile.types.each do |kind|
|
||||||
|
.grid.grid-cols-2
|
||||||
|
- if profile = @member.profile(kind)
|
||||||
%div
|
%div
|
||||||
%p.inline-block.px-3.py-px.mb-4.text-xs.font-semibold.tracking-wider.text-teal-900.uppercase.rounded-full.bg-teal-accent-400
|
=profile.Kind
|
||||||
Role ?
|
exists with name
|
||||||
%h5.mb-3.text-3xl.font-extrabold.leading-none.sm:text-4xl
|
=link_to profile.name , profile_path(profile) , class: "underline"
|
||||||
= @member.name
|
= link_to edit_profile_path(profile) do
|
||||||
.mb-8.text-gray-800
|
|
||||||
.prose= markdown(@member.bio)
|
|
||||||
.flex.items-center
|
|
||||||
%a.inline-flex.items-center.font-semibold.transition-colors.duration-200.text-deep-purple-accent-400.hover:text-deep-purple-800{"aria-label" => "", :href => "/"}
|
|
||||||
Learn More
|
|
||||||
%svg.inline-block.w-3.ml-2{:fill => "currentColor", :viewbox => "0 0 12 12"}
|
|
||||||
%path{:d => "M9.707,5.293l-5-5A1,1,0,0,0,3.293,1.707L7.586,6,3.293,10.293a1,1,0,1,0,1.414,1.414l5-5A1,1,0,0,0,9.707,5.293Z"}
|
|
||||||
|
|
||||||
-if @member == current_member or current_member.admin?
|
|
||||||
|
|
||||||
.flex.justify-around
|
|
||||||
= link_to edit_member_path(@member) do
|
|
||||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
||||||
Edit
|
Edit
|
||||||
- if @member.profile
|
=profile.Kind
|
||||||
= link_to edit_profile_path(@member.profile) do
|
|
||||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
|
||||||
Edit profile profile
|
|
||||||
-else
|
-else
|
||||||
= link_to new_profile_path do
|
%div Create new #{kind.capitalize} profile as
|
||||||
|
= link_to new_profile_path(kind: kind) do
|
||||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
||||||
Create profile profile
|
New
|
||||||
|
= kind.capitalize
|
||||||
|
|
||||||
.grid.grid-cols-3.gap-4
|
|
||||||
|
.grid.grid-cols-6.gap-4.mt-10.mx-10
|
||||||
-@member.entities.each do |entity|
|
-@member.entities.each do |entity|
|
||||||
%div= entity.type
|
%div= entity.type
|
||||||
%div= entity.name
|
%div= entity.name
|
||||||
%div= entity.value
|
%div= entity.value
|
||||||
= form_tag( destroy_member_session_path , {method: :delete } ) do
|
= form_tag( destroy_member_session_path , {method: :delete } ) do
|
||||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit}
|
%button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit}
|
||||||
Sign out
|
Sign out
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
= f.input :name
|
= f.input :name
|
||||||
= f.input :bio
|
= f.input :bio
|
||||||
|
= f.input :kind, :as => :hidden
|
||||||
= f.input :picture , as: :file , label: (@profile.picture.blank? ? "Add picture" : "Change picture (optional)")
|
= f.input :picture , as: :file , label: (@profile.picture.blank? ? "Add picture" : "Change picture (optional)")
|
||||||
|
|
||||||
.flex.justify-between.mt-4
|
.flex.justify-between.mt-4
|
||||||
@ -10,4 +11,4 @@
|
|||||||
= f.submit 'Save'
|
= f.submit 'Save'
|
||||||
|
|
||||||
%button.bg-cyan-200{class: button_classes}
|
%button.bg-cyan-200{class: button_classes}
|
||||||
= link_to 'Cancel', profiles_path
|
= link_to 'Cancel', member_path(current_member)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
.flex.justify-center
|
.flex.justify-center
|
||||||
.column
|
.column
|
||||||
.text-xl.m-4 Edit your profile profile
|
.text-xl.m-4
|
||||||
|
Edit your
|
||||||
|
=@profile.Kind
|
||||||
|
profile
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
.flex.justify-center
|
.flex.justify-center
|
||||||
.column
|
.column
|
||||||
.text-xl.m-4 Create your profile profile
|
.text-xl.m-4
|
||||||
|
Create your
|
||||||
|
=@profile.kind.capitalize
|
||||||
|
profile
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
.px-4.py-16.mx-auto.sm:max-w-xl.md:max-w-full.lg:max-w-screen-xl.md:px-24.lg:px-8.lg:py-20
|
.px-4.py-16.mx-auto.sm:max-w-xl.md:max-w-full.lg:max-w-screen-xl.md:px-24.lg:px-8.lg:py-20
|
||||||
.flex.flex-col.max-w-screen-lg.overflow-hidden.bg-white.border.rounded.shadow-sm.lg:flex-row.sm:mx-auto
|
.flex.justify-center
|
||||||
|
.px-4.py-4.text-center
|
||||||
|
%h1text-2xl.font-bold.tracking-tight.sm:text-4xl
|
||||||
|
= @profile.Kind
|
||||||
|
profile
|
||||||
|
.flex.py-4.flex-col.max-w-screen-lg.overflow-hidden.bg-white.border.rounded.shadow-sm.lg:flex-row.sm:mx-auto
|
||||||
.relative{:class => "lg:w-1/2"}
|
.relative{:class => "lg:w-1/2"}
|
||||||
-if @profile.picture_url
|
-if @profile.picture_url
|
||||||
= image_tag @profile.picture_url, class: "object-cover w-full lg:absolute h-80 lg:h-full"
|
= image_tag @profile.picture_url, class: "object-cover w-full lg:absolute h-80 lg:h-full"
|
||||||
|
18
test/policies/member_policy_test.rb
Normal file
18
test/policies/member_policy_test.rb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class MemberPolicyTest < ActiveSupport::TestCase
|
||||||
|
def test_scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_create
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_destroy
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user