Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

Adjustreact
杨树明 5 years ago
commit 7dbdf938e5

@ -2,7 +2,8 @@ class LiveLinksController < ApplicationController
before_action :require_login before_action :require_login
before_action :find_course, only: [:index, :create] before_action :find_course, only: [:index, :create]
before_action :user_course_identity, :teacher_allowed, only: [:create] before_action :user_course_identity, :teacher_allowed, only: [:create]
before_action :edit_auth, only: [:edit, :update, :destroy] before_action :edit_auth, only: [:edit, :update]
before_action :delete_auth, only: [:destroy]
def index def index
lives = @course.live_links lives = @course.live_links
@ -58,6 +59,10 @@ class LiveLinksController < ApplicationController
end end
def edit_auth def edit_auth
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin_or_business?
end
def delete_auth
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin? tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
end end
end end

@ -8,6 +8,10 @@ class LiveLink < ApplicationRecord
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" } validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }
def op_auth? def op_auth?
user == User.current || User.current.admin_or_business?
end
def delete_auth?
user == User.current || User.current.admin? user == User.current || User.current.admin?
end end
end end

@ -5,6 +5,7 @@ json.lives @lives do |live|
json.author_login live.user.login json.author_login live.user.login
json.author_img url_to_avatar(live.user) json.author_img url_to_avatar(live.user)
json.op_auth live.op_auth? json.op_auth live.op_auth?
json.delete_auth live.delete_auth?
json.created_at live.created_at.strftime('%Y-%m-%d') json.created_at live.created_at.strftime('%Y-%m-%d')
end end
json.my_live_id @my_live_id json.my_live_id @my_live_id

@ -72,13 +72,18 @@ class LiveItem extends Component{
</div> </div>
<p className="lineMiddle livesMain mt15 font-12"> <p className="lineMiddle livesMain mt15 font-12">
<span className="color-grey-9">创建时间{item.created_at}</span> <span className="color-grey-9">创建时间{item.created_at}</span>
{
item.op_auth ?
<span> <span>
<WordsBtn style="grey" onClick={()=>setLiveId(item.id)}>编辑</WordsBtn> {
<WordsBtn style="grey" className="ml30" onClick={()=>this.deleteLive(item.id)}>删除</WordsBtn> item.op_auth ?
</span>:"" <WordsBtn style="grey" onClick={()=>setLiveId(item.id)}>编辑</WordsBtn>:""
} }
{
item.delete_auth ?
<WordsBtn style="s" className="ml30" onClick={()=>this.deleteLive(item.id)}>删除</WordsBtn>
:""
}
</span>
</p> </p>
</div> </div>
) )

Loading…
Cancel
Save