Updated user_target autocomplete regex, removed unnecessary permission check
This commit is contained in:
@@ -88,5 +88,45 @@ $(function() {
|
|||||||
}], {
|
}], {
|
||||||
debounce: 300
|
debounce: 300
|
||||||
});
|
});
|
||||||
|
$('.md_editor .field_container_user .editor_field').textcomplete([{
|
||||||
|
// match up to 2 words (everything except some special characters)
|
||||||
|
// each word can have up to 16 characters (up to 32 total)
|
||||||
|
// words must be separated by a single space
|
||||||
|
match: /(^|\s)([^!"§$%&\/()=?.,;+*@\s]{1,16})$/,
|
||||||
|
search: function (text, callback, match) {
|
||||||
|
console.log("Searching " + text);
|
||||||
|
text = text.toLowerCase();
|
||||||
|
$.ajax("/users/suggestions", {
|
||||||
|
type: "post",
|
||||||
|
data: {name: text},
|
||||||
|
dataType: "json",
|
||||||
|
headers: {
|
||||||
|
"X-CSRF-Token": $('meta[name="csrf-token"]').attr("content")
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
callback(data);
|
||||||
|
},
|
||||||
|
error: function(xhr, status, err) {
|
||||||
|
console.error(err);
|
||||||
|
callback([]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
template: function(user) {
|
||||||
|
var name = user[0];
|
||||||
|
var ign = user[1];
|
||||||
|
if (name != ign) {
|
||||||
|
return name + " <small>(" + ign + ")</small>";
|
||||||
|
} else {
|
||||||
|
return ign;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cache: true,
|
||||||
|
replace: function (word) {
|
||||||
|
return "$1" + word[1] + " ";
|
||||||
|
}
|
||||||
|
}], {
|
||||||
|
debounce: 300
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Binary file not shown.
@@ -481,7 +481,6 @@ blockquote p {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.field_container_user {
|
.field_container_user {
|
||||||
position: relative;
|
|
||||||
.editor_field {
|
.editor_field {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class MessagesController < ApplicationController
|
class MessagesController < ApplicationController
|
||||||
|
|
||||||
before_filter :check_permission, only: :destroy
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if current_user
|
if current_user
|
||||||
@messages = Message.where(user_target: current_user).page(params[:page])
|
@messages = Message.where(user_target: current_user).page(params[:page])
|
||||||
@@ -67,19 +65,9 @@ class MessagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def message_params(add = [])
|
def message_params(add = [])
|
||||||
params[:message][:user_target_id] = User.find_by(ign: params[:message][:user_target].gsub(/[@ ]/,"")).try(:id)
|
params[:message][:user_target_id] = User.find_by(ign: params[:message][:user_target].strip).try(:id)
|
||||||
params[:message][:user_sender_id] = User.find_by(ign: params[:message][:user_sender]).id
|
params[:message][:user_sender_id] = User.find_by(ign: params[:message][:user_sender]).id
|
||||||
|
|
||||||
params.require(:message).permit([:text, :user_target_id, :user_sender_id])
|
params.require(:message).permit([:text, :user_target_id, :user_sender_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def check_permission
|
|
||||||
@message = Message.find(params[:id])
|
|
||||||
unless @message.user_target == current_user
|
|
||||||
flash[:alert] = "You are not allowed to view this message"
|
|
||||||
redirect_to home_statics_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="field_container_user">
|
<div class="field_container_user">
|
||||||
<% options = (defined?(options) && options || {}) %>
|
<% options = (defined?(options) && options || {}) %>
|
||||||
<% options[:class] = "#{options[:class]} editor_field" %>
|
<% options[:class] = "#{options[:class]} editor_field" %>
|
||||||
<% options[:placeholder] ||= "Enter user's name. prefix with \"@\" to get suggestions." %>
|
<% options[:placeholder] ||= "Enter user's name." %>
|
||||||
<%= text_field_tag name, content, options %>
|
<%= text_field_tag name, content, options %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user