Commit e5b74698 authored by Florian Hübsch's avatar Florian Hübsch
Browse files

Merge pull request #220 from ninjaconcept/220-for-ui-state-with-user-scope

Checking All Checkbox of Samples disables share button
parents 3746c3b3 be83acee
......@@ -106,10 +106,10 @@ module Chemotion
end
before do
samples = Sample.for_ui_state(params[:elements_filter][:sample])
reactions = Reaction.for_ui_state(params[:elements_filter][:reaction])
wellplates = Wellplate.for_ui_state(params[:elements_filter][:wellplate])
screens = Screen.for_ui_state(params[:elements_filter][:screen])
samples = Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample])
reactions = Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction])
wellplates = Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate])
screens = Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen])
top_secret_sample = samples.pluck(:is_top_secret).any?
top_secret_reaction = reactions.flat_map(&:samples).map(&:is_top_secret).any?
......@@ -160,7 +160,7 @@ module Chemotion
current_collection_id = ui_state[:currentCollectionId]
collection_id = params[:collection_id]
sample_ids = Sample.for_ui_state_with_collection(
sample_ids = Sample.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:sample],
CollectionsSample,
current_collection_id
......@@ -175,7 +175,7 @@ module Chemotion
CollectionsSample.find_or_create_by(sample_id: id, collection_id: collection_id)
}
reaction_ids = Reaction.for_ui_state_with_collection(
reaction_ids = Reaction.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:reaction],
CollectionsReaction,
current_collection_id
......@@ -190,7 +190,7 @@ module Chemotion
CollectionsReaction.find_or_create_by(reaction_id: id, collection_id: collection_id)
}
wellplate_ids = Wellplate.for_ui_state_with_collection(
wellplate_ids = Wellplate.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:wellplate],
CollectionsWellplate,
current_collection_id
......@@ -205,7 +205,7 @@ module Chemotion
CollectionsWellplate.find_or_create_by(wellplate_id: id, collection_id: collection_id)
}
screen_ids = Screen.for_ui_state_with_collection(
screen_ids = Screen.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:screen],
CollectionsScreen,
current_collection_id
......@@ -231,7 +231,7 @@ module Chemotion
collection_id = params[:collection_id]
current_collection_id = ui_state[:currentCollectionId]
Sample.for_ui_state_with_collection(
Sample.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:sample],
CollectionsSample,
current_collection_id
......@@ -239,7 +239,7 @@ module Chemotion
CollectionsSample.find_or_create_by(sample_id: id, collection_id: collection_id)
end
Reaction.for_ui_state_with_collection(
Reaction.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:reaction],
CollectionsReaction,
current_collection_id
......@@ -247,7 +247,7 @@ module Chemotion
CollectionsReaction.find_or_create_by(reaction_id: id, collection_id: collection_id)
end
Wellplate.for_ui_state_with_collection(
Wellplate.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:wellplate],
CollectionsWellplate,
current_collection_id
......@@ -255,7 +255,7 @@ module Chemotion
CollectionsWellplate.find_or_create_by(wellplate_id: id, collection_id: collection_id)
end
Screen.for_ui_state_with_collection(
Screen.for_user(current_user.id).for_ui_state_with_collection(
ui_state[:screen],
CollectionsScreen,
current_collection_id
......
......@@ -33,10 +33,10 @@ module Chemotion
end
post do
top_secret_sample = Sample.for_ui_state(params[:elements_filter][:sample]).pluck(:is_top_secret).any?
top_secret_reaction = Reaction.for_ui_state(params[:elements_filter][:reaction]).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_wellplate = Wellplate.for_ui_state(params[:elements_filter][:wellplate]).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_screen = Screen.for_ui_state(params[:elements_filter][:screen]).flat_map(&:wellplates).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_sample = Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample]).pluck(:is_top_secret).any?
top_secret_reaction = Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction]).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_wellplate = Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate]).flat_map(&:samples).map(&:is_top_secret).any?
top_secret_screen = Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen]).flat_map(&:wellplates).flat_map(&:samples).map(&:is_top_secret).any?
is_top_secret = top_secret_sample || top_secret_wellplate || top_secret_reaction || top_secret_screen
......@@ -75,10 +75,10 @@ module Chemotion
end
post do
sharing_allowed_sample = ElementsPolicy.new(current_user, Sample.for_ui_state(params[:elements_filter][:sample])).share?
sharing_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_ui_state(params[:elements_filter][:reaction])).share?
sharing_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_ui_state(params[:elements_filter][:wellplate])).share?
sharing_allowed_screen = ElementsPolicy.new(current_user, Screen.for_ui_state(params[:elements_filter][:screen])).share?
sharing_allowed_sample = ElementsPolicy.new(current_user, Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample])).share?
sharing_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction])).share?
sharing_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate])).share?
sharing_allowed_screen = ElementsPolicy.new(current_user, Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen])).share?
sharing_allowed = sharing_allowed_sample && sharing_allowed_reaction && sharing_allowed_wellplate && sharing_allowed_screen
......@@ -117,10 +117,10 @@ module Chemotion
end
post do
deletion_allowed_sample = ElementsPolicy.new(current_user, Sample.for_ui_state(params[:elements_filter][:sample])).destroy?
deletion_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_ui_state(params[:elements_filter][:reaction])).destroy?
deletion_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_ui_state(params[:elements_filter][:wellplate])).destroy?
deletion_allowed_screen = ElementsPolicy.new(current_user, Screen.for_ui_state(params[:elements_filter][:screen])).share?
deletion_allowed_sample = ElementsPolicy.new(current_user, Sample.for_user(current_user.id).for_ui_state(params[:elements_filter][:sample])).destroy?
deletion_allowed_reaction = ElementsPolicy.new(current_user, Reaction.for_user(current_user.id).for_ui_state(params[:elements_filter][:reaction])).destroy?
deletion_allowed_wellplate = ElementsPolicy.new(current_user, Wellplate.for_user(current_user.id).for_ui_state(params[:elements_filter][:wellplate])).destroy?
deletion_allowed_screen = ElementsPolicy.new(current_user, Screen.for_user(current_user.id).for_ui_state(params[:elements_filter][:screen])).share?
deletion_allowed = deletion_allowed_sample && deletion_allowed_reaction && deletion_allowed_wellplate && deletion_allowed_screen
......
......@@ -14,11 +14,11 @@ module Chemotion
end
before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Reaction.for_ui_state(params[:ui_state])).destroy?
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Reaction.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end
delete do
Reaction.for_ui_state(params[:ui_state]).destroy_all
Reaction.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end
end
......@@ -72,7 +72,7 @@ module Chemotion
end
delete do
Reaction.for_ui_state(params[:ui_state]).destroy_all
Reaction.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end
end
......
......@@ -15,11 +15,11 @@ module Chemotion
end
before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Sample.for_ui_state(params[:ui_state])).destroy?
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Sample.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end
delete do
Sample.for_ui_state(params[:ui_state]).destroy_all
Sample.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end
end
......@@ -31,7 +31,7 @@ module Chemotion
post do
ui_state = params[:ui_state]
currentCollectionId = ui_state[:currentCollectionId]
sample_ids = Sample.for_ui_state_with_collection(ui_state[:sample], CollectionsSample, currentCollectionId)
sample_ids = Sample.for_user(current_user.id).for_ui_state_with_collection(ui_state[:sample], CollectionsSample, currentCollectionId)
Sample.where(id: sample_ids).each do |sample|
#todo: extract method into Sample
subsample = sample.dup
......
......@@ -119,11 +119,11 @@ module Chemotion
end
before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_ui_state(params[:ui_state])).destroy?
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end
delete do
Screen.for_ui_state(params[:ui_state]).destroy_all
Screen.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end
end
......
......@@ -14,11 +14,11 @@ module Chemotion
end
before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Wellplate.for_ui_state(params[:ui_state])).destroy?
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Wellplate.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end
delete do
Wellplate.for_ui_state(params[:ui_state]).destroy_all
Wellplate.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end
end
......@@ -167,11 +167,11 @@ module Chemotion
end
before do
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_ui_state(params[:ui_state])).destroy?
error!('401 Unauthorized', 401) unless ElementsPolicy.new(@current_user, Screen.for_user(current_user.id).for_ui_state(params[:ui_state])).destroy?
end
delete do
Screen.for_ui_state(params[:ui_state]).destroy_all
Screen.for_user(current_user.id).for_ui_state(params[:ui_state]).destroy_all
end
end
......
......@@ -9,7 +9,8 @@ export default class ShareButton extends React.Component {
constructor(props) {
super(props);
this.state = {
isTopSecret: false
isTopSecret: false,
isDisabled: props.isDisabled
}
}
......@@ -21,6 +22,12 @@ export default class ShareButton extends React.Component {
PermissionStore.unlisten(this.onPermissionChange.bind(this));
}
componentWillReceiveProps(nextProps) {
this.setState({
isDisabled: nextProps.isDisabled
})
}
onPermissionChange(state) {
this.setState({
isTopSecret: state.is_top_secret
......@@ -60,13 +67,12 @@ export default class ShareButton extends React.Component {
}
render() {
const {isDisabled} = this.props;
const tooltip = (
<Tooltip>Share</Tooltip>
);
return (
<OverlayTrigger placement="bottom" overlay={tooltip}>
<Button bsStyle="info" onClick={this.showShareModal.bind(this)} disabled={isDisabled}>
<Button bsStyle="info" onClick={this.showShareModal.bind(this)} disabled={this.state.isDisabled}>
<i className="fa fa-share-alt"></i>
</Button>
</OverlayTrigger>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment