添加参赛应用的删除和修改功能以及添加相应的删除和修改权限

This commit is contained in:
wanglinchun 2014-04-22 10:59:50 +08:00
parent cc5b55ec9c
commit bc068eb12b
7 changed files with 79 additions and 32 deletions

View File

@ -75,7 +75,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.1.0)
rake (10.0.4)
rdoc (3.12.2)
json (~> 1.4)
ruby-openid (2.1.8)

View File

@ -1,4 +1,8 @@
class SoftapplicationsController < ApplicationController
before_filter :find_softapplication, only: [:edit, :update, :destroy]
before_filter :editable, only: [:edit, :update]
before_filter :destroyable, only: :destroy
# GET /softapplications
# GET /softapplications.json
def index
@ -71,7 +75,7 @@ class SoftapplicationsController < ApplicationController
# PUT /softapplications/1
# PUT /softapplications/1.json
def update
@softapplication = Softapplication.find(params[:id])
# @softapplication = Softapplication.find(params[:id])
respond_to do |format|
if @softapplication.update_attributes(params[:softapplication])
@ -92,11 +96,11 @@ class SoftapplicationsController < ApplicationController
# DELETE /softapplications/1
# DELETE /softapplications/1.json
def destroy
@softapplication = Softapplication.find(params[:id])
# @softapplication = Softapplication.find(params[:id])
@softapplication.destroy
respond_to do |format|
format.html { redirect_to softapplications_url }
format.html { redirect_to :back }
format.json { head :no_content }
end
end
@ -192,4 +196,24 @@ class SoftapplicationsController < ApplicationController
#format.api { render_api_ok }
end
end
private
def find_softapplication
@softapplication = Softapplication.find_by_id(params[:id])
end
def editable
unless @softapplication.editable_by? User.current
render_403
return false
end
end
def destroyable
unless @softapplication.destroyable_by? User.current
render_403
return false
end
end
end

View File

@ -181,7 +181,7 @@ class Attachment < ActiveRecord::Base
end
def pack?
!!(self.filename =~ /\.(zip|rar|tar|gz)$/i)
!!(self.filename =~ /\.(zip|rar|tar|gz|exe)$/i)
end
def thumbnailable?

View File

@ -7,7 +7,7 @@ class Softapplication < ActiveRecord::Base
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :contesting_softapplications, :dependent => :destroy
belongs_to :user
belongs_to :contest
has_many :contests, :through => :contesting_softapplications
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
@ -21,6 +21,13 @@ class Softapplication < ActiveRecord::Base
def set_commit(commit)
self.update_attribute(:commit, commit)
end
def editable_by? usr
usr.admin? || self.user == usr
end
def destroyable_by? usr
self.user == usr || usr.admin?
end
end

View File

@ -8,6 +8,7 @@
<td>
<%= link_to(c_softapplication.softapplication.name, softapplication_path(c_softapplication.softapplication)) %>
</td>
<td><%= link_to '删除', c_softapplication.softapplication, method: :delete, data: { confirm: '您确定要删除吗?' } %></td>
</tr></br>
</div>
<div style="padding-left: 68px">

View File

@ -1,28 +1,43 @@
<!--add by huang-->
<div class="clearfix"></div>
<div id="footer" style="margin-left:-5px;padding-top: 50px;clear: both;font-size: 12px;">
<div style="border-top:solid 1px #C6E9F1;width:940px;margin-left:auto;margin-right:auto;margin-bottom: 5px;margin-top: -50px;"></div>
<div class="base_footer">
<div align="center">
<!--gcm-->
<p>
<span>主办单位:</span>
<span class="footer_text_link"><%= link_to "国防科学技术大学并行与分布处理国家重点实验室","http://www.nudt.edu.cn/ArticleShow.asp?ID=47",:target=>"_blank"%></span>
<span id="copyright">版权@2007~2014</span>
<span id="contact_us" class="footer_text_link"><%= link_to "联系我们","http://forge.trustie.net/projects/2/member",:target=>"_blank"%></span>
<span id="record"class="footer_text_link"><%= link_to "湘ICP备09019772","http://www.miibeian.gov.cn/"%></span>
</p>
<div id="logo_link">
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/nudt.png',:size=>'100x30',:alt=>"国防科学技术大学计算机学院"),"http://www.nudt.edu.cn/special.asp?classid=12"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/peking_eecs.png',:size=>'100x30',:alt=>"北京大学信息科学技术学院软件研究所"), "http://eecs.pku.edu.cn"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/buaa_scse.png',:size=>'100x30',:alt=>"北京航空航天大学计算机学院"), "http://scse.buaa.edu.cn/"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/iscas.png',:size=>'100x30',:alt=>"中国科学院软件研究所"), "http://www.iscas.ac.cn"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/inforbus.png',:size=>'100x30',:alt=>"山东中创软件商用中间件股份有限公司"), "http://www.inforbus.com"%></span>
</div>
<!--gcm-->
</div>
</div>
<div style="border-top:solid 1px #C6E9F1;width:940px;margin-left:auto;margin-right:auto;margin-bottom: 5px;margin-top: -50px;">
</div>
<div class="base_footer">
<div align="center">
<!--gcm-->
<p>
<span>主办单位:</span>
<span class="footer_text_link"><%= link_to "国防科学技术大学并行与分布处理国家重点实验室","http://www.nudt.edu.cn/ArticleShow.asp?ID=47",:target=>"_blank"%></span>
<span id="copyright">版权@2007~2014</span>
<span id="contact_us" class="footer_text_link"><%= link_to "联系我们","http://forge.trustie.net/projects/2/member",:target=>"_blank"%></span>
<span id="record"class="footer_text_link"><%= link_to "湘ICP备09019772","http://www.miibeian.gov.cn/"%></span>
</p>
<div id="logo_link">
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/nudt.png',:size=>'100x30',:alt=>"国防科学技术大学计算机学院"),"http://www.nudt.edu.cn/special.asp?classid=12"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/peking_eecs.png',:size=>'100x30',:alt=>"北京大学信息科学技术学院软件研究所"), "http://eecs.pku.edu.cn"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/buaa_scse.png',:size=>'100x30',:alt=>"北京航空航天大学计算机学院"), "http://scse.buaa.edu.cn/"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/iscas.png',:size=>'100x30',:alt=>"中国科学院软件研究所"), "http://www.iscas.ac.cn"%></span>
<span class="footer_logo_link"><%= link_to image_tag('/images/footer_logo/inforbus.png',:size=>'100x30',:alt=>"山东中创软件商用中间件股份有限公司"), "http://www.inforbus.com"%></span>
</div>
<!--gcm-->
</div>
</div>
</div>
<div class="debug">
<%= debug(params) if Rails.env.development? %>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46523987-1', 'trustie.net');
ga('send', 'pageview');
</script>
</div>

View File

@ -1,4 +1,4 @@
<h1>Listing softapplications</h1>
<h1>参赛应用</h1>
<table>
<tr>