3 Commits
pm ... memory

Author SHA1 Message Date
MrYummy
0aad3bb71a Added choice of project, r/w perms, and fixed up some css 2017-07-04 22:27:07 +02:00
MrYummy
0f74795159 Added basic hexfile reading that respects r/w perms 2017-07-01 04:48:52 +02:00
MrYummy
3bfc74045f hi 2017-06-21 01:59:02 +02:00
59 changed files with 206 additions and 766 deletions

Binary file not shown.

View File

@@ -51,4 +51,4 @@ $(function(){
return time + " " + unit + tail; return time + " " + unit + tail;
} }
}); });
}); });

View File

@@ -14,4 +14,5 @@
//= require app //= require app
//= require editor //= require editor
//= require highlight //= require highlight
//= require jquery-textcomplete //= require jquery-textcomplete
//= require memory

View File

@@ -88,45 +88,5 @@ $(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
});
}); });

View File

@@ -0,0 +1,26 @@
$(function() {
$('td').focus(function() {
if (this.id.split("-")[0] == "memory") {
$(this).css("background-color", "lightblue")
}
});
var data = [];
$('td').keydown(function() {
data.push(this.id, $(this).html().substr(0, 2)); //position, value
})
$('td').blur(function() {
$(this).css("background", "none");
if ((id_i = data.indexOf(this.id) != -1) && data[id_i+1] != $(this).html().substr(0, 2)) {
$(this).css("color", "darkgreen");
var int_id = this.id.split("-")[1]
$.post("/memory/update_memory?project="+$(this).closest("table").data("project")+"&file="+Math.floor((int_id/2048)+1)+"&mem_id="+int_id%2048+"&value="+$(this).html().substr(0, 2));
data.splice(id_i, 2);
}
});
$('select').change(function() {
$.get("/memory/table?project="+$(this).data("project")+"&file="+$(this).find("option:selected").text()+".hex")
});
});

View File

@@ -480,10 +480,6 @@ blockquote p {
padding: 4em 1em 1em; padding: 4em 1em 1em;
} }
} }
.field_container_user {
.editor_field {
}
}
} }
ul.dropdown-menu { ul.dropdown-menu {
@@ -650,7 +646,6 @@ tr.spacer {
} }
.profile-action { .profile-action {
font-size: 0;
float: right; float: right;
} }
@@ -1032,3 +1027,12 @@ nav.pagination {
border-radius: 0.2em; border-radius: 0.2em;
text-shadow: none; text-shadow: none;
} }
.memory-table {
width: 980px;
margin: auto;
text-align: center;
th, td {
height: 20px;
border: 1px solid black;
}
}

View File

@@ -75,4 +75,4 @@ class ApplicationController < ActionController::Base
!!(current_user && current_user.confirmed?) !!(current_user && current_user.confirmed?)
end end
end end

View File

@@ -8,8 +8,16 @@ class BlogpostsController < ApplicationController
end end
def show def show
@comment = Comment.new(blogpost: @post) if @post
@comments = @post.comments.page(params[:page]) @comment = Comment.new(blogpost: @post)
@comments = @post.comments.page(params[:page])
respond_to do |format|
format.html
format.json {render json: @post.attributes.merge(replies: Comment.where(blogpost: @post).ids).to_json}
end
else
respond_to {|format| format.json {render json: Comment.find_by(id: params[:id][1..-1]).try(:attributes).to_json}}
end
end end
def new def new
@@ -64,7 +72,9 @@ class BlogpostsController < ApplicationController
def set_post def set_post
if params[:id] if params[:id]
@post = Blogpost.find(params[:id]) unless action_name == "show" && params[:id][0].downcase == "c"
@post = Blogpost.find(params[:id])
end
end end
end end
@@ -75,4 +85,4 @@ class BlogpostsController < ApplicationController
end end
end end
end end

View File

@@ -2,6 +2,12 @@ class CommentsController < ApplicationController
include MailerHelper include MailerHelper
def show
respond_to do |format|
format.json {render json: @comment.attributes.to_json}
end
end
def edit def edit
@comment = Comment.find(params[:id]) @comment = Comment.find(params[:id])
if mod? || @comment.author.is?(current_user) if mod? || @comment.author.is?(current_user)
@@ -72,4 +78,4 @@ class CommentsController < ApplicationController
def comment_params def comment_params
params.require(:comment).permit(:content) params.require(:comment).permit(:content)
end end
end end

View File

@@ -92,4 +92,4 @@ class ForumsController < ApplicationController
a = [:name, :position, :role_read_id, :role_write_id] + add a = [:name, :position, :role_read_id, :role_write_id] + add
params.require(:forum).permit(a) params.require(:forum).permit(a)
end end
end end

View File

@@ -92,4 +92,4 @@ class ForumthreadsController < ApplicationController
a += add a += add
params.require(:forumthread).permit(a) params.require(:forumthread).permit(a)
end end
end end

View File

@@ -0,0 +1,54 @@
class MemoryController < ApplicationController
before_filter :logged_in
def index
current_uuid = current_user.uuid.gsub("-", "")
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/players/#{current_uuid}")
psjson = JSON.parse(File.read("projects.json"))
@projects = psjson["owns"] + psjson["read"] + psjson["write"]
@project_names = @projects.collect{|p| (data = JSON.parse(File.read(File.expand_path("../..")+"/projects/#{p}/project.json")))["name"] + " | #{"own" if data["owner"] == current_uuid}#{"write" if data["write"].include? current_uuid}#{"read" if data["read"].include? current_uuid}"}
end
def list
render :index
end
def table
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project].gsub(/[^a-zA-Z0-9-]/,"")[0..35]}")
@data = []
Dir.glob('*').reverse.each do |f|
File.open(Dir.pwd+"/#{f}") do |file|
@data.concat(file.read.unpack("C*").map{|h| h.to_s(16)})
unless (parse = JSON.parse((jf = File.open(Dir.pwd+"/project.json")).read))["read"].include? current_user.uuid.gsub("-","")
@can_edit = true
end
@name = parse["name"]
jf.close
end
end
end
def update_memory
Dir.chdir("/etc/minecraft/redstoner/plugins/JavaUtils/memory/projects/#{params[:project].gsub(/[^a-zA-Z0-9-]/,"")[0..35]}")
unless params[:mem_id].to_i > JSON.parse(File.read("project.json"))["size"] || (/[^A-Fa-f0-9]/.match params[:value])
new_text = ""
File.open("#{params[:file]}.hex"){|f| new_text = f.read.unpack("C*").collect{|h| h.to_s(16)}}
new_text[params[:mem_id].to_i] = params[:value]
File.open("#{params[:file]}.hex", "w") do |f|
f.write((new_text.collect{|h| h.to_s.to_i(16)}).pack("C*").force_encoding("UTF-8"))
end
render nothing: true
end
end
private
def logged_in
unless current_user
flash[:alert] = "Please log in before viewing memory files."
redirect_to home_statics_path
end
end
end

View File

@@ -1,77 +0,0 @@
class MessagerepliesController < ApplicationController
def edit
@reply = Messagereply.find(params[:id])
if mod? || @reply.author.is?(current_user)
else
flash[:alert] = "You are not allowed to edit this reply"
redirect_to @reply.message
end
end
def create
message = Message.find(params[:message_id])
if [message.user_sender, message.user_target].include? current_user
@reply = Messagereply.new(reply_params)
@reply.user_author = current_user
@reply.message = message
if @reply.save
if false
@reply.send_new_message_reply_mail
end
Message.find(params[:message_id]).update_attributes(user_hidden: nil, user_unread_id: current_user.id)
position = message.replies.count - 1
page = position / Kaminari.config.default_per_page + 1
redirect_to message_path(@reply.message, page: page) + "#reply-#{@reply.id}", notice: 'Reply created!'
else
flash[:alert] = "Could not create reply."
redirect_to Message.find(params[:message_id])
end
else
flash[:alert] = "You are not allowed to create replies."
redirect_to Message.find(params[:message_id])
end
end
def update
@reply = Messagereply.find(params[:id])
if mod? || @reply.author.is?(current_user)
old_content = @reply.text_was
if @reply.update_attributes(reply_params)
if false
@reply.send_new_reply_mail(old_content)
end
flash[:notice] = "Reply updated!"
position = @reply.message.replies.index(@reply)
page = position / Kaminari.config.default_per_page + 1
redirect_to message_path(@reply.message, page: page) + "#reply-#{@reply.id}"
else
flash[:alert] = "There was a problem while updating your reply"
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this reply"
redirect_to @reply.message
end
end
def destroy
@reply = Messagereply.find(params[:id])
if mod? || @reply.author.is?(current_user)
if @reply.destroy
flash[:notice] = "Reply deleted!"
else
flash[:alert] = "There was a problem while deleting this reply"
end
else
flash[:alert] = "You are not allowed to delete this reply"
end
redirect_to @reply.message
end
private
def reply_params
params.require(:messagereply).permit(:text)
end
end

View File

@@ -1,128 +0,0 @@
class MessagesController < ApplicationController
before_filter :set_current
def set_current
User.current = current_user
end
before_filter :check_permission, only: [:show, :edit, :update, :destroy]
def index
if current_user
@messages = Message.where("(user_sender_id = ? OR user_target_id = ?) AND (user_hidden_id != ? OR user_hidden_id IS NULL)", current_user.id, current_user.id, current_user.id).page(params[:page])
else
flash[:alert] = "Please log in to see your private messages."
redirect_to blogposts_path
end
end
def show
Message.find(@message.id).update_attributes(user_unread: nil) unless @message.user_unread == current_user
@replies = @message.replies.page(params[:page])
end
def edit
unless mod? || @message.author.is?(current_user)
flash[:alert] = "You are not allowed to edit this message!"
redirect_to @message
end
end
def new
if current_user
@message = Message.new
else
flash[:alert] = "Please log in to send a private message."
redirect_to blogposts_path
end
end
def create
unless message_params[:user_target_id]
flash[:alert] = "Please enter a valid IGN before sending."
redirect_to new_message_path
return
end
if message_params[:subject].blank?
flash[:alert] = "Please write a subject before sending."
redirect_to new_message_path
return
elsif message_params[:text].blank?
flash[:alert] = "Please write a message before sending."
redirect_to new_message_path
return
end
@message = Message.new(message_params)
@message.user_target = User.find(@message.user_target_id)
@message.user_unread = User.find(@message.user_unread_id) if @message.user_unread_id
if @message.save
@message.send_new_message_mail
flash[:notice] = "Message sent!"
redirect_to messages_path
else
flash[:alert] = "Something went wrong while creating your message."
render action: "new"
end
end
def update
if mod? || @message.user_sender.is?(current_user)
@message.user_editor_id = current_user.id
@message.attributes = message_params
if @message.save
redirect_to @message, notice: 'Message has been updated.'
else
flash[:alert] = "There was a problem while updating the message."
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this message!"
redirect_to @message
end
end
def destroy
if [@message.user_target, @message.user_sender].include?(current_user)
if @message.destroy
flash[:notice] = "Message deleted!"
else
unless @message.user_hidden
flash[:alert] = "There was a problem while deleting this message."
else
Message.find(@message.id).update_attributes(user_hidden: current_user)
end
end
else
flash[:alert] = "You are not allowed to delete this message."
end
redirect_to messages_path
end
def destroy_all
Message.destroy_all(user_target_id: current_user.id)
if Message.where(user_target_id: current_user.id).empty?
flash[:notice] = "Your messages have been deleted!"
else
flash[:alert] = "There was a problem while deleting your messages."
end
redirect_to messages_path
end
def message_params(add = [])
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_hidden_id] = User.find_by(ign: params[:message][:user_hidden]).try(:id)
params[:message][:user_unread_id] = User.find_by(ign: params[:message][:user_unread]).try(:id)
params.require(:message).permit([:subject, :text, :user_target_id, :user_sender_id, :user_hidden_id, :user_unread_id])
end
private
def check_permission
@message = Message.find(params[:id])
unless [@message.user_target, @message.user_sender].include? current_user
flash[:alert] = "You are not allowed to view this message"
redirect_to home_statics_path
end
end
end

View File

@@ -69,4 +69,4 @@ class ThreadrepliesController < ApplicationController
def reply_params def reply_params
params.require(:threadreply).permit(:content) params.require(:threadreply).permit(:content)
end end
end end

View File

@@ -30,6 +30,10 @@ class UsersController < ApplicationController
end end
def show def show
respond_to do |format|
format.html
format.json {render json: @user.attributes.slice("id", "uuid", "ign", "name", "about", "donor", "confirmed", "last_seen", "created_at").to_json}
end
end end
# SIGNUP # SIGNUP

View File

@@ -90,4 +90,4 @@ module ApplicationHelper
https://www.youtube-nocookie.com/embed/\\1?theme=light&vq=hd720&hd=1&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1&html5=1&start=\\3'> https://www.youtube-nocookie.com/embed/\\1?theme=light&vq=hd720&hd=1&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1&html5=1&start=\\3'>
</iframe>") </iframe>")
end end
end end

View File

@@ -24,4 +24,4 @@ module MailerHelper
end end
end end
end end
end end

View File

@@ -0,0 +1,2 @@
module MemoryHelper
end

View File

@@ -52,4 +52,4 @@ module UsersHelper
end end
end end
end end

View File

@@ -44,10 +44,4 @@ class RedstonerMailer < ActionMailer::Base
@user = user @user = user
mail(to: @user.email, subject: "Email change on Redstoner.com") mail(to: @user.email, subject: "Email change on Redstoner.com")
end end
def new_message_mail(user, message)
@user = user
@message = message
mail(to: @user.email, subject: "#{message.user_sender.name} sent you a new message")
end
end end

View File

@@ -61,4 +61,4 @@ class Comment < ActiveRecord::Base
background_mailer(mails) background_mailer(mails)
end end
end end

View File

@@ -1,75 +0,0 @@
class Message < ActiveRecord::Base
include MailerHelper
belongs_to :user_sender, class_name: "User", foreign_key: "user_sender_id"
belongs_to :user_target, class_name: "User", foreign_key: "user_target_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
belongs_to :user_hidden, class_name: "User", foreign_key: "user_hidden_id"
belongs_to :user_unread, class_name: "User", foreign_key: "user_unread_id"
validates_presence_of :user_sender, :user_target, :text, :subject
validates_length_of :text, in: 1..8000
validates_length_of :subject, in: 1..2000
has_many :messagereplies
accepts_nested_attributes_for :messagereplies
before_destroy :do_destroy?
def do_destroy?
if user_hidden || user_sender == user_target
return true
else
update_attributes(user_hidden: User.current)
return false
end
end
def to_s
subject
end
def sender
@sender ||= if self.user_sender.present?
user_sender
else
User.first
end
end
def target
@target ||= if self.user_target.present?
user_target
else
User.first
end
end
def editor
@editor ||= (self.user_editor || User.first)
end
def edited?
!!user_editor_id
end
def replies
messagereplies
end
def send_new_message_mail
begin
mail = RedstonerMailer.new_message_mail(user_target, self)
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create new_message_mail (view) for message#: #{@message.id}, user: #{@user.name}, #{@user.email}"
Rails.logger.error e.message
Rails.logger.error "---"
end
background_mailer([mail])
end
end

View File

@@ -1,67 +0,0 @@
class Messagereply < ActiveRecord::Base
include MailerHelper
include UsersHelper
belongs_to :message
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
validates_presence_of :text
validates_length_of :text, in: 1..8000
def get_message
message
end
def author
@author ||= if self.user_author.present?
user_author
else
User.first
end
end
def editor
# can be nil
@editor ||= user_editor
end
def edited?
!!user_editor_id
end
def send_new_reply_mail(old_content = "")
users = mentions(content) - mentions(old_content)
# thread + replies
posts = message.replies.to_a
posts << message if message.author.mail_own_message_reply?
# only send "reply" mail when reply is new
unless old_content.present?
posts.each do |post|
# don't send mail to the author of this reply, don't send to banned/disabled users
if post.author != author && post.author.normal? && post.author.confirmed? # &&
users << post.author if post.author.mail_other_thread_reply?
end
end
end
# making sure we don't send multiple mails to the same user
users.uniq!
mails = []
users.each do |usr|
begin
mails << RedstonerMailer.new_thread_reply_mail(usr, self)
rescue => e
Rails.logger.error "---"
Rails.logger.error "WARNING: Failed to create new_thread_reply_mail (view) for reply#: #{@self.id}, user: #{@user.name}, #{@user.email}"
Rails.logger.error e.message
Rails.logger.error "---"
end
end
background_mailer(mails)
end
end

View File

@@ -64,4 +64,4 @@ class Threadreply < ActiveRecord::Base
end end
background_mailer(mails) background_mailer(mails)
end end
end end

View File

@@ -24,8 +24,6 @@ class User < ActiveRecord::Base
has_many :blogposts has_many :blogposts
has_many :comments has_many :comments
cattr_accessor :current
# foo.bar.is?(current_user) # foo.bar.is?(current_user)
def is? (user) def is? (user)
self == user self == user

View File

@@ -8,4 +8,4 @@
<%= text_area_tag name, content, options %> <%= text_area_tag name, content, options %>
<div class="preview"><i>(Loading...)</i></div> <div class="preview"><i>(Loading...)</i></div>
</div> </div>
</div> </div>

View File

@@ -1,8 +0,0 @@
<div class="md_editor">
<div class="field_container_user">
<% options = (defined?(options) && options || {}) %>
<% options[:class] = "#{options[:class]} editor_field" %>
<% options[:placeholder] ||= "Enter user's name." %>
<%= text_field_tag name, content, options %>
</div>
</div>

View File

@@ -1,4 +1,5 @@
<% title "News" %> <% title "News" %>
<h1>News</h1> <h1>News</h1>
<%= link_to 'Make new Post', new_blogpost_path, class: "btn blue" if mod? %> <%= link_to 'Make new Post', new_blogpost_path, class: "btn blue" if mod? %>
<div id="posts"> <div id="posts">

View File

@@ -38,4 +38,4 @@
<p><%= f.submit "Update thread", class: "btn blue left" %></p> <p><%= f.submit "Update thread", class: "btn blue left" %></p>
<% end %> <% end %>
<%= button_to "Delete thread", @thread, :method => "delete", data: {confirm: "Delete thread & comments forever?"}, class: "btn red right" %> <%= button_to "Delete thread", @thread, :method => "delete", data: {confirm: "Delete thread & comments forever?"}, class: "btn red right" %>
<div class="clear"></div> <div class="clear"></div>

View File

@@ -32,4 +32,4 @@
<%= f.hidden_field :forum_id %> <%= f.hidden_field :forum_id %>
<p><%= f.submit "Create thread", class: "btn blue left" %></p> <p><%= f.submit "Create thread", class: "btn blue left" %></p>
<div class="clear"></div> <div class="clear"></div>
<% end %> <% end %>

View File

@@ -44,4 +44,4 @@
<% else %> <% else %>
<p>Please <%= link_to "Log in", login_path(return_path: request.env['PATH_INFO']), action: "new" %> to post a reply.</p> <p>Please <%= link_to "Log in", login_path(return_path: request.env['PATH_INFO']), action: "new" %> to post a reply.</p>
<% end %> <% end %>
</div> </div>

View File

@@ -25,4 +25,4 @@
</div> </div>
<%= render partial: "/layouts/footer" %> <%= render partial: "/layouts/footer" %>
</body> </body>
</html> </html>

View File

@@ -0,0 +1,5 @@
<%= form_tag url_for(controller: "memory", action: "table"), method: :get do %>
<%= select_tag "project", options_for_select(@projects.collect.with_index{|p, i| [@project_names[i], p]}) %>
<br><br>
<%= submit_tag "Load table", name: nil, class: "btn blue" %>
<% end %>

View File

@@ -0,0 +1,17 @@
<h1 style="text-align:center"><%= title @name + (" (read-only)" if !@can_edit).to_s %></h1>
<table class="memory-table", data-project="<%=params[:project]%>">
<tr>
<% ["Address","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"].each do |i| %>
<th><b><%=i%></b></th>
<% end %>
</tr>
<% @data.in_groups_of(16).each_with_index do |row, rindex| %>
<tr>
<td><b><%=(rindex*16).to_s(16).upcase.rjust(6, "0")%></b></td>
<% row.each_with_index do |hex, hindex| %>
<td contenteditable="<%=!!@can_edit%>" id="memory-<%=(16*rindex)+hindex%>"><%=hex.to_s.upcase.rjust(2, "0")%></td>
<% end %>
</tr>
<% end %>
</table>
<br>

View File

@@ -1,5 +0,0 @@
<%= form_for [reply.get_message, reply] do |f| %>
<%= render partial: "md_editor", locals: {name: "messagereply[text]", content: reply.text} %>
<p><%= f.submit "Reply", class: "btn blue" %></p>
<% end %>

View File

@@ -1,17 +0,0 @@
<div class="item-group thread-reply with-avatar" id="reply-<%= reply.id %>">
<div class="header">
<%= link_to(reply.author.avatar(64), reply.author, title: reply.author.ign) %>
<%= render partial: "users/username", locals: { user: reply.author } %>
<%= link_to "#reply-#{reply.id}" do %>
<%= ago reply.created_at %>
<% end %>
<%= link_to "edit", edit_message_messagereply_path(reply.message, reply), class: "editlink" if mod? || reply.author.is?(current_user) %>
<div class="clear-right"></div>
</div>
<div class="items">
<div class="item content">
<%= render_md(reply.text).html_safe %>
</div>
</div>
</div>

View File

@@ -1,15 +0,0 @@
<% title "Edit Message Reply: #{@reply.message.subject}" %>
<%
position = @reply.message.replies.index(@reply)
page = position / Kaminari.config.default_per_page + 1
%>
<%= link_to "Messages", messages_path %> → <%= link_to @reply.message, message_path(@reply.message, page: page) + "#reply-#{@reply.id}" %> → Edit reply
<h1>Edit reply</h1>
<%= form_for [@reply.message, @reply] do |f| %>
<%= render partial: "md_editor", locals: {name: "messagereply[text]", content: @reply.text} %>
<p><%= f.submit "Reply", class: "btn blue left" %></p>
<% end %>
<p><%= button_to "Delete reply", [@reply.message, @reply], method: "delete", data: {confirm: "Delete reply forever?"}, class: "btn red right" %></p>
<div class="clear"></div>

View File

@@ -1,17 +0,0 @@
<% title "Edit Thread: #{@message}" %>
<h1>Edit thread</h1>
<%= link_to "Messages", messages_path %> → <%= link_to @message, @message %> → Edit Message
<%= form_for @message do |f|%>
<div class="table-cell full-width">
<%= f.text_field :subject, placeholder: "Subject" %>
</div>
<br>
<%= render partial: "md_editor", locals: {name: "message[text]", content: @message.text} %>
<p><%= f.submit "Update message", class: "btn blue left" %></p>
<%= f.hidden_field :user_sender, value: @message.user_sender %>
<%= f.hidden_field :user_target, value: @message.user_target %>
<% end %>
<%= button_to "Delete ", @message, :method => "delete", data: {confirm: "Delete message & comments forever?"}, class: "btn red right" %>
<div class="clear"></div>

View File

@@ -1,60 +0,0 @@
<% if @messages.any? %>
<%= link_to "delete all messages", destroy_all_messages_path, method: "post", class: "btn blue right", data: {confirm: "Delete all of your messages forever?"} %>
<% end %>
<%= link_to "create new message", new_message_path, class: "btn blue right" %>
<br>
<h2>
<% if Message.where("(user_target_id = ? OR user_sender_id = ?) AND user_hidden_id != ?", current_user.id, current_user.id, current_user.id).any? %>
Your private messages:
<% else %>
You have no private messages.
<% end %>
</h2>
<div id="forum_groups">
<% @messages.each do |message| %>
<div class="item-group with-avatar">
<div class="header">
<%
if current_user == message.user_sender
user = message.user_target
else
user = message.user_sender
end
%>
<%= link_to(user.avatar(64), user, title: user.ign) %>
<%= render partial: "users/username", locals: { user: user } %>
<span style="font-size:16px">
&nbsp;
<span class="<%= "bold" if message.user_unread_id && message.user_unread != current_user %>"><%= link_to message.subject, message %></span>
&nbsp; | &nbsp;
</span>
<%= ago message.created_at %>
<div class="right">
<%= link_to "Delete message", message, :method => "delete", class: "editlink", data: {confirm: "Delete this message forever?"} %>
</div>
<div class="clear-right"></div>
</div>
<div class="items">
<div class="item">
<%= truncate message.text, length: 20, omission: "..." %>
<div class="item-info items bold">
<% if rpl = message.replies.last %>
<%= rpl.author.name %>
<%
position = message.replies.count - 1
page = position / Kaminari.config.default_per_page + 1
%>
<%= link_to "replied", message_path(message, page: page) + "#reply-#{rpl.id}" %>
<%= ago rpl.created_at %>.
<% else %>
No replies yet.
<% end %>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<% end %>
<%= paginate @messages %>
</div>

View File

@@ -1,26 +0,0 @@
<h1>New Message</h1>
<%= form_for @message do |f| %>
</table>
<tr>
<td>
<%= render partial: "md_editor_user", locals: {name: "message[user_target]", content: params[:user_target]} %>
</td>
</tr>
<br>
<tr>
<td>
<%= f.text_field :subject, placeholder: "Subject" %>
</td>
</tr>
<br><br>
<tr>
<td>
<%= render partial: "md_editor", locals: {name: "message[text]", content: params[:text]} %>
</td>
</tr>
</table>
<%= f.hidden_field :user_sender, value: current_user %>
<%= f.hidden_field :user_unread, value: current_user %>
<br>
<p><%= f.submit "Send Message", class: "btn blue left" %></p>
<% end %>

View File

@@ -1,33 +0,0 @@
<%= link_to "Messages", messages_path %>
<h1><%= title @message.subject %></h1>
<div class="item-group thread with-avatar" id="message-<%= @message.id %>">
<div class="header">
<%= link_to(@message.sender.avatar(64), @message.sender, title: @message.sender.ign) %>
<%= render partial: "users/username", locals: { user: @message.sender } %>
<%= link_to p do %>
<%= ago @message.created_at %>
<% end %>
<%= link_to "edit", edit_message_path(@message), class: "editlink" if mod? || @message.sender.is?(current_user) %>
<div class="clear-right"></div>
</div>
<div class="items">
<% if @message.edited? %>
<div class="item edited">
Last edited <%= ago @message.updated_at %> by <%= link_to @message.editor.name, @message.editor %>.
</div>
<% end %>
<div class="item content">
<%= render_md(@message.text).html_safe %>
</div>
</div>
</div>
<div id="replies">
<h3><%= "#{pluralize(@message.replies.size, 'reply')}." %></h3>
<% @replies.each do |reply| %>
<%= render partial: "messagereplies/reply", locals: {reply: reply} %>
<% end %>
<%= paginate @replies %>
<%= render partial: "messagereplies/new", locals: {reply: Messagereply.new(message: @message)} %>
</div>

View File

@@ -1,28 +0,0 @@
<div style="font-family: 'Oswald','Calibri','Arial','DejaVu Sans','Open Sans','Lucida Sans','Lucida Grande','Lucida Sans Unicode',sans-serif; background: #F2F2F2">
<div style="color: #3f3f3f; width: 600px; max-width: 100%; padding: 2em 0; margin: auto;">
Hi <%= @user.name %>!
<p><%= link_to @message.user_sender.name, user_url(@message.user_sender), style: "text-decoration: none; color: #4096EE;" %> has sent you a new message!</p>
<blockquote>
<%= render_md(@message.text).html_safe %>
</blockquote>
<p><%= link_to "Click here", messages_url, style: "text-decoration: none; color: #4096EE;" %> to view your current messages.</p>
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_url(role: "staff"), style: "text-decoration: none; color: #4096EE;" %> in-game or on the forums!</p>
<p>Your Redstoner team</p>
</div>
<div style="background: #444; width: 100%; color: #fff; margin: auto; text-align: center; display: inline-block;">
<div style="margin: 2em;">
<p><i>Too much spam? Change <%= link_to "your notification settings", edit_notifications_user_url(@user), style: "text-decoration: none; color: #4096EE;" %>!</i></p>
<p>You can contact us via:
<%= link_to "Website", root_url, style: "text-decoration: none; color: #4096EE;" %> |
<%= link_to "Twitter", "https://twitter.com/RedstonerServer", style: "text-decoration: none; color: #4096EE;" %> |
<%= link_to "Google+", "https://google.com/+Redstoner", style: "text-decoration: none; color: #4096EE;" %> |
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
</p>
</div>
</div>
</div>

View File

@@ -29,4 +29,4 @@
</p> </p>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -30,4 +30,4 @@
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %> <%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
</p> </p>
</div> </div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<%= form_for [reply.thread, reply] do |f| %> <%= form_for [reply.thread, reply] do |f| %>
<%= render partial: "md_editor", locals: {name: "threadreply[content]", content: reply.content} %> <%= render partial: "md_editor", locals: {name: "threadreply[content]", content: reply.content} %>
<p><%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue" %></p> <p><%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue" %></p>
<% end %> <% end %>

View File

@@ -12,4 +12,4 @@
<p><%= f.submit "Reply", class: "btn blue left" %></p> <p><%= f.submit "Reply", class: "btn blue left" %></p>
<% end %> <% end %>
<p><%= button_to "Delete reply", [@reply.thread, @reply], method: "delete", data: {confirm: "Delete reply forever?"}, class: "btn red right" %></p> <p><%= button_to "Delete reply", [@reply.thread, @reply], method: "delete", data: {confirm: "Delete reply forever?"}, class: "btn red right" %></p>
<div class="clear"></div> <div class="clear"></div>

View File

@@ -87,4 +87,4 @@
<span class='red-alert'>This user has not confirmed his email!</span> <span class='red-alert'>This user has not confirmed his email!</span>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -19,4 +19,4 @@
</div> </div>
<% end %> <% end %>
<%= paginate @users %> <%= paginate @users %>
</div> </div>

View File

@@ -1,19 +1,14 @@
<% title @user.name %> <% title @user.name %>
<div id="user-info"> <div id="user-info">
<div class="profile-action"> <% if @user.is?(current_user) || (mod? && current_user.role >= @user.role) %>
<% if session[:original_user_id] %> <div class="profile-action" ><%= link_to "edit profile", edit_user_path(@user), :class => "btn blue" %></div>
<%= link_to "revert", revert_path, :class => "btn blue" %> <% end %>
<% elsif admin? %> <div class="profile-action" >
<% if !session[:original_user_id] && admin? %>
<%= link_to "become this user", become_path(user: @user), :class => "btn blue" %> <%= link_to "become this user", become_path(user: @user), :class => "btn blue" %>
<% end %> <% elsif session[:original_user_id] %>
<% if @user.is?(current_user) || (mod? && current_user.role >= @user.role) %> <%= link_to "revert", revert_path, :class => "btn blue" %>
<%= link_to "edit profile", edit_user_path(@user), :class => "btn blue" %>
<% end %>
<% if @user.is?(current_user) %>
<%= link_to "private messages (#{Message.where.not(user_unread: current_user).count})", messages_path, :class => "btn blue" %>
<% elsif current_user %>
<%= link_to "Send this user a message", new_message_path(user_target: @user.ign), :class => "btn blue" %>
<% end %> <% end %>
</div> </div>

View File

@@ -10,7 +10,7 @@ default: &default
development: development:
<<: *default <<: *default
database: redstoner-web database: redstoner-web
username: root username: web
production: production:
<<: *default <<: *default
@@ -24,4 +24,4 @@ test:
adapter: sqlite3 adapter: sqlite3
database: db/test.sqlite3 database: db/test.sqlite3
pool: 5 pool: 5
timeout: 5000 timeout: 5000

View File

@@ -43,4 +43,4 @@ Redstoner::Application.configure do
password: ENV["GMAIL_PASSWORD"], password: ENV["GMAIL_PASSWORD"],
} }
end end

View File

@@ -29,6 +29,15 @@ Redstoner::Application.routes.draw do
end end
end end
resources :memory do
collection do
get 'list'
get 'table'
post 'update_memory'
end
end
resources :forumgroups, path: '/forums/groups' resources :forumgroups, path: '/forums/groups'
resources :forums, path: '/forums' resources :forums, path: '/forums'
resources :forumthreads, path: '/forums/threads' do resources :forumthreads, path: '/forums/threads' do
@@ -41,13 +50,6 @@ Redstoner::Application.routes.draw do
end end
end end
resources :messages do
resources :messagereplies, path: 'replies'
collection do
post 'destroy_all'
end
end
# get '/status' => 'status#show' # get '/status' => 'status#show'
get 'login' => 'sessions#new' get 'login' => 'sessions#new'

View File

@@ -1,14 +0,0 @@
class CreateMessages < ActiveRecord::Migration
def change
create_table :messages do |t|
t.text :message
t.references :user_sender
t.references :user_target
t.references :user_editor
t.references :user_hidden
t.references :user_unread
t.timestamps null: true
end
end
end

View File

@@ -1,5 +0,0 @@
class ChangeMessageToText < ActiveRecord::Migration
def change
rename_column :messages, :message, :text
end
end

View File

@@ -1,5 +0,0 @@
class AddSubjectToMessages < ActiveRecord::Migration
def change
add_column :messages, :subject, :string
end
end

View File

@@ -1,13 +0,0 @@
class CreateMessagereplies < ActiveRecord::Migration
def change
create_table :messagereplies do |t|
t.text :text
t.references :user_author
t.references :user_editor
t.references :message
t.timestamps null: true
end
end
end

View File

@@ -11,10 +11,10 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170613021450) do ActiveRecord::Schema.define(version: 20160926220738) do
create_table "blogposts", force: :cascade do |t| create_table "blogposts", force: :cascade do |t|
t.string "title", limit: 191 t.string "title"
t.text "content", limit: 65535 t.text "content", limit: 65535
t.integer "user_author_id", limit: 4 t.integer "user_author_id", limit: 4
t.integer "user_editor_id", limit: 4 t.integer "user_editor_id", limit: 4
@@ -32,14 +32,14 @@ ActiveRecord::Schema.define(version: 20170613021450) do
end end
create_table "forumgroups", force: :cascade do |t| create_table "forumgroups", force: :cascade do |t|
t.string "name", limit: 191 t.string "name"
t.integer "position", limit: 4 t.integer "position", limit: 4
t.integer "role_read_id", limit: 4 t.integer "role_read_id", limit: 4
t.integer "role_write_id", limit: 4 t.integer "role_write_id", limit: 4
end end
create_table "forums", force: :cascade do |t| create_table "forums", force: :cascade do |t|
t.string "name", limit: 191 t.string "name"
t.integer "position", limit: 4 t.integer "position", limit: 4
t.integer "role_read_id", limit: 4 t.integer "role_read_id", limit: 4
t.integer "role_write_id", limit: 4 t.integer "role_write_id", limit: 4
@@ -52,7 +52,7 @@ ActiveRecord::Schema.define(version: 20170613021450) do
end end
create_table "forumthreads", force: :cascade do |t| create_table "forumthreads", force: :cascade do |t|
t.string "title", limit: 191 t.string "title"
t.text "content", limit: 65535 t.text "content", limit: 65535
t.boolean "sticky", default: false t.boolean "sticky", default: false
t.boolean "locked", default: false t.boolean "locked", default: false
@@ -65,54 +65,33 @@ ActiveRecord::Schema.define(version: 20170613021450) do
end end
create_table "info", force: :cascade do |t| create_table "info", force: :cascade do |t|
t.string "title", limit: 191 t.string "title"
t.text "content", limit: 65535 t.text "content", limit: 65535
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "labels", force: :cascade do |t| create_table "labels", force: :cascade do |t|
t.string "name", limit: 191 t.string "name"
t.string "color", limit: 191 t.string "color"
end
create_table "messagereplies", force: :cascade do |t|
t.text "text", limit: 65535
t.integer "user_author_id", limit: 4
t.integer "user_editor_id", limit: 4
t.integer "message_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "messages", force: :cascade do |t|
t.text "text", limit: 65535
t.integer "user_sender_id", limit: 4
t.integer "user_target_id", limit: 4
t.integer "user_editor_id", limit: 4
t.integer "user_hidden_id", limit: 4
t.integer "user_unread_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.string "subject", limit: 191
end end
create_table "register_tokens", force: :cascade do |t| create_table "register_tokens", force: :cascade do |t|
t.string "uuid", limit: 32, null: false t.string "uuid", null: false
t.string "token", limit: 6, null: false t.string "token", null: false
t.string "email", limit: 191, null: false t.string "email", null: false
end end
add_index "register_tokens", ["uuid"], name: "index_register_tokens_on_uuid", unique: true, using: :btree add_index "register_tokens", ["uuid"], name: "index_register_tokens_on_uuid", unique: true, using: :btree
create_table "roles", force: :cascade do |t| create_table "roles", force: :cascade do |t|
t.string "name", limit: 191 t.string "name"
t.integer "value", limit: 4 t.integer "value", limit: 4
t.string "color", limit: 191 t.string "color"
end end
create_table "sessions", force: :cascade do |t| create_table "sessions", force: :cascade do |t|
t.string "session_id", limit: 191, null: false t.string "session_id", null: false
t.text "data", limit: 65535 t.text "data", limit: 65535
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
@@ -131,20 +110,20 @@ ActiveRecord::Schema.define(version: 20170613021450) do
end end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "uuid", limit: 191, null: false t.string "uuid", null: false
t.string "name", limit: 191, null: false t.string "name", null: false
t.string "password_digest", limit: 191, null: false t.string "password_digest", null: false
t.string "ign", limit: 191, null: false t.string "ign", null: false
t.string "email", limit: 191, null: false t.string "email", null: false
t.text "about", limit: 65535 t.text "about", limit: 65535
t.string "last_ip", limit: 191 t.string "last_ip"
t.string "skype", limit: 191 t.string "skype"
t.boolean "skype_public", default: false t.boolean "skype_public", default: false
t.string "youtube", limit: 191 t.string "youtube"
t.string "youtube_channelname", limit: 191 t.string "youtube_channelname"
t.string "twitter", limit: 191 t.string "twitter"
t.boolean "donor", default: false t.boolean "donor", default: false
t.string "email_token", limit: 191 t.string "email_token"
t.boolean "confirmed", default: false t.boolean "confirmed", default: false
t.datetime "last_seen" t.datetime "last_seen"
t.integer "role_id", limit: 4, null: false t.integer "role_id", limit: 4, null: false

View File

@@ -39,28 +39,3 @@ User.create!(
password_confirmation: "123456789", password_confirmation: "123456789",
role: Role.get(:superadmin) role: Role.get(:superadmin)
) )
User.create!(
uuid: "7f52491ab5d64c11b4a43806db47a101",
ign: "Yummy_",
name: "Yummy",
email: "yummy@example.com",
password: "123456789", # high seructity!
password_confirmation: "123456789",
role: Role.get(:superadmin)
)
User.create!(
uuid: "62fe35da05ae437ea44b4deae1be1dc4",
ign: "Logal",
email: "logal@example.com",
password: "123456789", # high seructity!
password_confirmation: "123456789",
role: Role.get(:superadmin)
)
Message.create!(
user_sender_id: 2,
user_target_id: 2,
text: "This is a very long message that I will be using to test a plentitude of things. :)",
created_at: Time.utc(0).to_datetime,
subject: "Hello there!"
)