forked from hugopl/reviewit
-
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.
Fixed bug hugopl#3 - Add project owners
Allow to specify which users are the owner of the project Only owners can edit project information
- Loading branch information
Renato Araujo Oliveira Filho
committed
Apr 19, 2017
1 parent
f5a2db0
commit 6be3d6d
Showing
10 changed files
with
114 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
window.projects = function() { | ||
var tag = $('#project_users'); | ||
if (!tag.length) | ||
return; | ||
var tags = $('#project_owners, #project_members'); | ||
tags.each(function(index) { | ||
var value = tags[index] | ||
var field = value.dataset.field | ||
var users = value.dataset.users.split('|'); | ||
var myself = value.dataset.myself; | ||
|
||
var before_add = function(event, ui) { | ||
return users.indexOf(ui.tagLabel) !== -1; | ||
}; | ||
|
||
var before_remove = function(event, ui) { | ||
var its_me = ui.tagLabel === myself; | ||
if (its_me) | ||
alert('You need to participate on your own project.'); | ||
return !its_me; | ||
}; | ||
|
||
$(tags[index]).tagit({ | ||
fieldName: 'project['+field+'][]', | ||
availableTags: users, | ||
autocomplete: { | ||
delay: 0, | ||
minLength: 1 | ||
}, | ||
allowDuplicates: false, | ||
removeConfirmation: true, | ||
beforeTagAdded: before_add, | ||
beforeTagRemoved: before_remove, | ||
placeholderText: 'Type the ' + field + ' names' | ||
}); | ||
}) | ||
|
||
var users = tag[0].dataset.users.split('|'); | ||
var myself = tag[0].dataset.myself; | ||
var before_add = function(event, ui) { | ||
return users.indexOf(ui.tagLabel) !== -1; | ||
}; | ||
var before_remove = function(event, ui) { | ||
var its_me = ui.tagLabel === myself; | ||
if (its_me) | ||
alert('You need to participate on your own project.'); | ||
return !its_me; | ||
}; | ||
tag.tagit({ | ||
fieldName: 'project[users][]', | ||
availableTags: users, | ||
autocomplete: { | ||
delay: 0, | ||
minLength: 1 | ||
}, | ||
allowDuplicates: false, | ||
removeConfirmation: true, | ||
beforeTagAdded: before_add, | ||
beforeTagRemoved: before_remove, | ||
placeholderText: 'Type the user names' | ||
}); | ||
}; |
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
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,4 @@ | ||
class ProjectsUsers < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :project | ||
end |
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
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,7 +1,9 @@ | ||
%h1 Edit Project | ||
|
||
= link_to 'Destroy project', @project, method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
id: 'project_destroy', | ||
class: 'reject button' | ||
= render partial: 'form', locals: { action: 'update' } | ||
- if @project.owner?(current_user) | ||
= link_to 'Destroy project', @project, method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
id: 'project_destroy', | ||
class: 'reject button' | ||
= render partial: 'form', locals: { action: 'update' } | ||
- else | ||
%strong= 'Only project onwers can edit the project' |
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,5 @@ | ||
class AddOwnerToProjectsUsers < ActiveRecord::Migration | ||
def change | ||
add_column :projects_users, :owner, :boolean, :default => true | ||
end | ||
end |
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