-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d0fd6c
commit 04f5009
Showing
7 changed files
with
150 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
class Ability | ||
include CanCan::Ability | ||
include CanCan::Ability | ||
|
||
def initialize(user) | ||
alias_action :new_request, :send_request, to: :request | ||
def initialize(user) | ||
alias_action :new_request, :send_request, to: :request | ||
|
||
@user = user || User.new | ||
@user.role = 'guest' if @user.role.blank? | ||
@user = user || User.new | ||
@user.role = 'guest' if @user.role.blank? | ||
|
||
send(@user.role.downcase) | ||
end | ||
send(@user.role.downcase) | ||
end | ||
|
||
# Admin user can do anything | ||
def admin | ||
can :manage, :all | ||
end | ||
# Admin user can do anything | ||
def admin | ||
can :manage, :all | ||
end | ||
|
||
# Guest, a non-signed in user, can only view public articles | ||
def guest | ||
can :read, Article do |article| | ||
article.private == false || article.private == nil | ||
end | ||
can :read, User | ||
end | ||
# Guest, a non-signed in user, can only view public articles | ||
def guest | ||
can :read, Article do |article| | ||
article.private == false || article.private == nil | ||
end | ||
can :read, User | ||
end | ||
|
||
# Member is a registered user | ||
def member | ||
guest | ||
# Member's account type determines his/her abilities | ||
send @user.account.downcase | ||
end | ||
# Member is a registered user | ||
def member | ||
guest | ||
# Member's account type determines his/her abilities | ||
send @user.account.downcase | ||
end | ||
|
||
# Types of user account: free, basic, academic, pro and enterprise | ||
# Types of user account: free, basic, academic, pro and enterprise | ||
|
||
def free | ||
# Article | ||
cannot :manage, Article, private: true | ||
can :manage, Article do |article| | ||
(article.private == false && article.user_id == @user.id) | ||
end | ||
# Appraisal | ||
can :manage, Appraisal do |appraisal| | ||
appraisal.member.user_id == @user.id | ||
end | ||
# Participation | ||
can :manage, Member, user_id: @user.id | ||
# User | ||
can [:read, :update], User, id: @user.id | ||
end | ||
def free | ||
# Article | ||
cannot :manage, Article, private: true | ||
can :manage, Article do |article| | ||
(article.private == false && article.user_id == @user.id) | ||
end | ||
# Appraisal | ||
can :manage, Appraisal do |appraisal| | ||
appraisal.member.user_id == @user.id | ||
end | ||
# Participation | ||
can :manage, Member, user_id: @user.id | ||
# User | ||
can [:read, :update], User, id: @user.id | ||
end | ||
|
||
def basic | ||
free | ||
can :participate_in, Article do |article| | ||
article.members.include? @user | ||
end | ||
can :manage, Article do |article| | ||
(article.user_id == @user.id) | ||
end | ||
end | ||
def basic | ||
free | ||
can :participate_in, Article do |article| | ||
article.members.include? @user | ||
end | ||
can :manage, Article do |article| | ||
(article.user_id == @user.id) | ||
end | ||
end | ||
|
||
def academic | ||
basic | ||
def academic | ||
basic | ||
|
||
can :create_report, Article do |article| | ||
article.user_id == @user.id | ||
end | ||
can :import_export_excel, Article do |article| | ||
article.user_id == @user.id | ||
end | ||
end | ||
can :create_report, Article do |article| | ||
article.user_id == @user.id | ||
end | ||
can :import_export_excel, Article do |article| | ||
article.user_id == @user.id | ||
end | ||
end | ||
|
||
def pro | ||
academic | ||
can :create_report, Article | ||
can :create_pdf_report, Article | ||
can :import_export_excel, Article | ||
end | ||
def pro | ||
academic | ||
can :create_report, Article | ||
can :create_pdf_report, Article | ||
can :import_export_excel, Article | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
h1 Editing User | ||
- page_title "User Profile" | ||
|
||
= render 'form', user: @user | ||
- content_for :left_frame do | ||
= render 'users/profile_sidepanel' | ||
|
||
#container-box | ||
.widget | ||
.widget-header | ||
i.icon-list-ul | ||
h3 = @user.name | ||
.well.well-widget-content | ||
.widget-content-title Editing user profile | ||
|
||
= form_with model: @user do |form| | ||
.control-group | ||
= form.label :name, for: 'user_name', class: "control-label" | ||
.controls | ||
= form.text_field :name, class: 'input-xxlarge' | ||
|
||
.control-group | ||
= form.label :bio, class: "control-label" | ||
.controls | ||
= form.text_area :bio, class: 'input-xxlarge tinymce', rows: 10 | ||
|
||
= tinymce | ||
|
||
#toolbar.button-toolbar | ||
= form.submit 'Save', class:"btn btn-primary" | ||
= link_to user_path(@user), class:"btn" do | ||
i.icon-remove | ||
| Cancel | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "User Profile", :type => :request do | ||
let(:bingley) { create :bingley } | ||
let(:darcy) { create :darcy } | ||
let(:valid_attributes) { | ||
{ name: "Mr. Bingley", email: "bingley@netherfield.net", bio: '£5,000 a year' } | ||
} | ||
let(:invalid_attributes) { | ||
{ name: "John Doe", email: " " } | ||
} | ||
|
||
context "without logged in user" do | ||
it "allows to read a user's profile" do | ||
get user_path(bingley) | ||
expect(response).to redirect_to( new_user_session_path ) | ||
end | ||
|
||
it "won't allow the user to edit" do | ||
get edit_user_path(bingley) | ||
expect(response).to redirect_to( new_user_session_path ) | ||
end | ||
end | ||
|
||
context "with logged in user" do | ||
before { | ||
sign_in bingley | ||
} | ||
it "allows to read a user's profile" do | ||
get user_path(darcy) | ||
expect(response.body).to include(bingley.name) | ||
end | ||
|
||
it "allows the user to edit" do | ||
get edit_user_path(bingley) | ||
expect(response).to be_successful | ||
end | ||
|
||
it "allows the user to edit his bio" do | ||
patch user_path(bingley), params: {user: valid_attributes} | ||
expect(bingley.reload.bio).to eq '£5,000 a year' | ||
end | ||
|
||
it "won't allow the user to edit" do | ||
get edit_user_path(darcy) | ||
expect(response).to redirect_to(root_path) | ||
follow_redirect! | ||
expect(response.body).to include('You are not authorized') | ||
end | ||
end | ||
|
||
end |