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

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
@ -22,5 +22,12 @@ class Softapplication < ActiveRecord::Base
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,7 +1,8 @@
<!--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 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">
@ -24,5 +25,19 @@
<!--gcm-->
</div>
</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>