完成组织域名申请消息重构
This commit is contained in:
parent
f321082fdc
commit
55d16eb589
|
@ -636,31 +636,73 @@ class OrganizationsController < ApplicationController
|
|||
end
|
||||
def apply_subdomain
|
||||
organization = Organization.find(params[:id])
|
||||
@applied_message_count = AppliedMessage.where(:applied_id => organization.id, :name => params[:domain].downcase).count
|
||||
@applied_message_count = AppliedMessage.where(:applied_id => organization.id, :name => params[:domain].downcase, :status => 1).count
|
||||
# 如果申请过该名字,怎不能重复申请
|
||||
if @applied_message_count > 0
|
||||
@flag = true
|
||||
return
|
||||
@flag = 1
|
||||
else
|
||||
admins = User.where("admin=1")
|
||||
admins.each do |admin|
|
||||
AppliedMessage.create(:user_id => admin.id, :applied_id => organization.id, :applied_type => 'ApplySubdomain', :viewed => 0, :satus => 1, :applied_user_id => User.current.id, :name => params[:domain].downcase)
|
||||
AppliedMessage.create(:user_id => admin.id, :applied_id => organization.id, :applied_type => 'Organization', :viewed => 0, :satus => 1, :applied_user_id => User.current.id, :name => params[:domain].downcase)
|
||||
# OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain].downcase)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# stauts: 0:申请 ,2:申请人收到已接受消息
|
||||
# @flag 1:申请同名提醒, 2:操作的时候已经被人提前处理了
|
||||
def agree_apply_subdomain
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
OrgMessage.find(params[:act_id]).update_attribute(:viewed, 1)
|
||||
if Secdomain.where("pid=? and sub_type=2",@organization.id).count > 0
|
||||
domain = Secdomain.where("pid=? and sub_type=2",params[:organization_id]).first
|
||||
Secdomain.update(domain.id, :subname => params[:org_domain])
|
||||
organization_id = params[:organization_id]
|
||||
org_domain = params[:org_domain]
|
||||
@applied_message = AppliedMessage.find(params[:ma_id])
|
||||
# 处理的时候判断是否有人已经处理了
|
||||
if @applied_message.status == 0
|
||||
# 事务处理:消息和数据的创建应该是同步的
|
||||
ActiveRecord::Base.transaction do
|
||||
applied_messages = AppliedMessage.where(:applied_type => "Organization", :applied_id => organization_id, :name => org_domain, :status => 0)
|
||||
applied_messages.update_all(:status => 2, :viewed => true, :updated_at => Time.now)
|
||||
secdomain = Secdomain.where(:pid => organization_id, :sub_type => 2)
|
||||
if secdomain.count > 0
|
||||
domain = Secdomain.where("pid=? and sub_type=2",organization_id).first
|
||||
Secdomain.update(domain.id, :subname => params[:org_domain])
|
||||
else
|
||||
Secdomain.create(:sub_type => 2, :pid => organization_id, :subname => params[:org_domain])
|
||||
end
|
||||
# 自己处理自己的消息则不需要另外发送消息
|
||||
if User.current.id != @applied_message.applied_user_id
|
||||
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_id => organization_id, :applied_type => 'Organization', :viewed => 0, :satus => 2, :applied_user_id => User.current.id, :name => org_domain.downcase)
|
||||
end
|
||||
@applied_message.status = 2
|
||||
@applied_message.updated_at = Time.now
|
||||
end
|
||||
else
|
||||
Secdomain.create(:sub_type => 2, :pid => params[:organization_id], :subname => params[:org_domain])
|
||||
@flag = 2
|
||||
end
|
||||
if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0
|
||||
OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain])
|
||||
end
|
||||
|
||||
# stauts: 0:申请 ,2:申请人收到已接受消息, 4:已拒绝
|
||||
# @flag 1:申请同名提醒, 2:操作的时候已经被人提前处理了
|
||||
def refused_apply_subdomain
|
||||
organization_id = params[:organization_id]
|
||||
org_domain = params[:org_domain]
|
||||
@applied_message = AppliedMessage.find(params[:ma_id])
|
||||
# 多人同时操作处理
|
||||
secdomain = Secdomain.where(:pid => organization_id, :sub_type => 2)
|
||||
# 处理过程中,如果已经被其他管理员处理,则弹框提示
|
||||
if @applied_message.status == 0
|
||||
# 事务处理:消息和数据的创建应该是同步的
|
||||
ActiveRecord::Base.transaction do
|
||||
applied_messages = AppliedMessage.where(:applied_type => "Organization", :applied_id => organization_id, :name => org_domain, :status => 0)
|
||||
applied_messages.update_all(:status => 4, :viewed => true, :updated_at => Time.now)
|
||||
# 自己处理自己的消息则不需要另外发送消息
|
||||
if User.current.id != @applied_message.applied_user_id
|
||||
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_id => organization_id, :applied_type => 'Organization', :viewed => 0, :satus => 4, :applied_user_id => User.current.id, :name => org_domain.downcase)
|
||||
end
|
||||
@applied_message.status = 4
|
||||
@applied_message.updated_at = Time.now
|
||||
end
|
||||
else
|
||||
@flag = 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,6 +46,10 @@ module ApplicationHelper
|
|||
@objs = paginateHelper @attachments,25
|
||||
end
|
||||
|
||||
# 判断当前用户能否对消息进行操作
|
||||
def allow_to_show applied_message
|
||||
(User.current.id == applied_message.user_id && applied_message.status == 0) ? true : false
|
||||
end
|
||||
|
||||
# 获取竞赛的管理人员
|
||||
def contest_managers contest
|
||||
|
|
|
@ -134,10 +134,6 @@ module UsersHelper
|
|||
end
|
||||
|
||||
end
|
||||
# 判断当前用户能否对消息进行操作
|
||||
def allow_to_show applied_message
|
||||
(User.current.id == applied_message.user_id && applied_message.status == 0) ? true : false
|
||||
end
|
||||
|
||||
# 项目申请消息通过状态判断用户
|
||||
# status(1:申请的消息;2:已操作过该消息(包括同意或者拒绝,消息状态更新);3:拒绝消息;4:被拒人收到消息;5:拒绝者收到消息;6:同意后申请人收到消息;7:同意后批准人收到消息)
|
||||
|
|
|
@ -10,6 +10,7 @@ class Organization < ActiveRecord::Base
|
|||
has_many :users, :through => :org_members
|
||||
has_many :files
|
||||
has_many :org_messages, :class_name => 'OrgMessage', :dependent => :destroy
|
||||
has_many :applied_messages, :class_name => 'AppliedMessage', :dependent => :destroy
|
||||
acts_as_attachable
|
||||
validates_uniqueness_of :name
|
||||
after_create :save_as_org_activity, :add_default_subfields
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
<div class="sy_popup_con02" >
|
||||
<ul class="sy_popup_tishi ">
|
||||
<li>
|
||||
<% if @flag %>
|
||||
<% if @flag == 1 %>
|
||||
<p>当前组织已申请过该域名,请耐心等待管理员的审批,审批完成后系统会以消息的形式通知您</p>
|
||||
<% elsif @flag == 2 %>
|
||||
<p>已经被其他管理员抢先一步处理了</p>
|
||||
<% else %>
|
||||
<p>您的申请已提交,系统会以消息的形式通知您结果</p>
|
||||
<% end %>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<% if @flag == 2 %>
|
||||
var htmlvalue = "<%= escape_javascript(render :partial => 'organizations/applied_organization_domain_tip') %>";
|
||||
pop_box_new(htmlvalue,380,250);
|
||||
<% end %>
|
||||
$("#applied_project_<%= @applied_message.id %>").html('<%= escape_javascript( render :partial => 'users/applied_organization_sundomain', :locals => {:ma => @applied_message}) %>');
|
|
@ -1 +1 @@
|
|||
$("#agree_apply_subdomain_<%= params[:act_id] %>").text("已同意申请");
|
||||
<%= render "organizations/organization_message_ajax_tip" %>
|
|
@ -0,0 +1 @@
|
|||
<%= render "organizations/organization_message_ajax_tip" %>
|
|
@ -0,0 +1,16 @@
|
|||
<div class="shortMessageWidth">
|
||||
<li class="homepageNewsPortrait fl">
|
||||
<%=link_to image_tag(url_to_avatar(ma.applied), :width => "30", :height => "30"), organization_path(ma.applied_id), :target => '_blank' %>
|
||||
</li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<%=link_to ma.applied.name, organization_path(ma.applied_id), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
|
||||
<span class='homepageNewsType fl'>申请子域名:</span>
|
||||
</li>
|
||||
<li class="messageInformationContents">
|
||||
<%= ma.name %>
|
||||
</li>
|
||||
</div>
|
||||
<li class="messageOperateContents fl">
|
||||
<span><%= render :partial => "users/user_message_organization_applied_action", :locals => {:ma => ma} %></span>
|
||||
</li>
|
||||
<li class="homepageNewsTime fr"><%= time_tag(ma.updated_at).html_safe %> </li>
|
|
@ -25,6 +25,10 @@
|
|||
<ul class="homepageNewsList fl" id="applied_project_<%= ma.id %>">
|
||||
<%= render :partial => "users/applied_project_content", :locals =>{:ma => ma} %>
|
||||
</ul>
|
||||
<% elsif ma && ma.applied_type == "Organization" %>
|
||||
<ul class="homepageNewsList fl" id="applied_project_<%= ma.id %>">
|
||||
<%= render :partial => "users/applied_organization_sundomain", :locals =>{:ma => ma} %>
|
||||
</ul>
|
||||
<!-- 匿评成绩申诉 -->
|
||||
<% elsif ma && ma.applied_type == "StudentWorksScoresAppeal" %>
|
||||
<ul class="homepageNewsList fl">
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<% ma = ma.nil? ? local_assigns[:ma] : ma %>
|
||||
<% if allow_to_show(ma) %>
|
||||
<%= link_to "同意", agree_apply_subdomain_organizations_path(:organization_id => ma.applied_id, :org_domain => ma.name, :user_id => ma.applied_user_id, :ma_id => ma.id),
|
||||
:remote => true, :method => :post, :class => "link-blue", :style => "font-size: 14px;" %> |
|
||||
<%= link_to "拒绝", refused_apply_subdomain_organizations_path(:organization_id => ma.applied_id, :org_domain => ma.name, :user_id => ma.applied_user_id, :ma_id => ma.id),
|
||||
:remote => true, :method => :post, :class => "link-blue",:style => "font-size: 14px;" %>
|
||||
<% elsif ma.status == 2 %>
|
||||
<span style="font-size:14px;">已同意</span>
|
||||
<% elsif ma.status == 4 %>
|
||||
<span style="font-size:14px;">已拒绝</span>
|
||||
<% end %>
|
|
@ -103,6 +103,7 @@ RedmineApp::Application.routes.draw do
|
|||
post 'reset_excellent_teacher'
|
||||
post 'reset_excellent_student'
|
||||
post 'agree_apply_subdomain'
|
||||
post 'refused_apply_subdomain'
|
||||
post 'update_field_by_admin'
|
||||
post 'reset_update_field_by_admin'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue