Class: GroupsUsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- GroupsUsersController
- Defined in:
- app/controllers/groups_users_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /groups_users POST /groups_users.json.
-
#destroy ⇒ Object
DELETE /groups_users/1 DELETE /groups_users/1.json.
-
#edit ⇒ Object
GET /groups_users/1/edit.
-
#index ⇒ Object
GET /groups_users GET /groups_users.json.
-
#new ⇒ Object
GET /groups_users/new GET /groups_users/new.json.
-
#register ⇒ Object
registration of existing user from signup page.
-
#show ⇒ Object
GET /groups_users/1 GET /groups_users/1.json.
-
#show_group ⇒ Object
show and manage users for a group.
-
#update ⇒ Object
PUT /groups_users/1 PUT /groups_users/1.json.
Instance Method Details
#create ⇒ Object
POST /groups_users POST /groups_users.json
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/groups_users_controller.rb', line 56 def create @group = @groups.find(params[:groups_user][:group_id]) raise CanCan::AccessDenied.new("Permission error") unless current_user.group_admin?(@group) @groups_user = GroupsUser.new(params[:groups_user]) user = User.find_by_email(params[:user_email]) if user.nil? flash[:error] = "Kein Benutzer mit dieser E-Mail gefunden" render :action => "new" return elsif @group.groups_users.where("groups_users.user_id = ?", user.id).any? flash[:error] = "Benutzer gehört schon zu dieser Gruppe" render :action => "new" return end @groups_user.user = user @groups_user.granted = true respond_to do |format| if @groups_user.save format.html { redirect_to group_path(@groups_user.group), :notice => 'Benutzer wurde erfolgreich zur Gruppe hinzugefügt.' } format.json { render :json => @groups_user, :status => :created, :location => @groups_user } else format.html { render :action => "new" } format.json { render :json => @groups_user.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /groups_users/1 DELETE /groups_users/1.json
105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/groups_users_controller.rb', line 105 def destroy @groups = admin_groups(@groups) @groups_user = GroupsUser.where(:group_id => @groups).find(params[:id]) group = @groups_user.group @groups_user.destroy respond_to do |format| format.html { redirect_to group_path(group), :notice => "Benutzer wurde erfolgreich aus der Gruppe entfernt." } format.json { head :ok } end end |
#edit ⇒ Object
GET /groups_users/1/edit
46 47 48 49 50 51 52 |
# File 'app/controllers/groups_users_controller.rb', line 46 def edit @groups = admin_groups(@groups) @groups_user = GroupsUser.where(:group_id => @groups).find(params[:id]) @mail_body = mail_body rescue raise CanCan::AccessDenied.new("Permission error") end |
#index ⇒ Object
GET /groups_users GET /groups_users.json
9 10 11 12 13 14 15 16 |
# File 'app/controllers/groups_users_controller.rb', line 9 def index @groups = admin_groups(@groups) @groups_users = GroupsUser.where(:group_id => @groups).joins(:group, :user).order('groups.name,users.login') respond_to do |format| format.html # index.html.erb format.json { render :json => @groups_users } end end |
#new ⇒ Object
GET /groups_users/new GET /groups_users/new.json
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/groups_users_controller.rb', line 32 def new @group = @groups.find(params[:group]) raise CanCan::AccessDenied.new("Permission error") unless current_user.group_admin?(@group) @groups_user = GroupsUser.new(:group => @group) respond_to do |format| format.html # new.html.erb format.json { render :json => @groups_user } end rescue raise CanCan::AccessDenied.new("Permission error") end |
#register ⇒ Object
registration of existing user from signup page
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/controllers/groups_users_controller.rb', line 118 def register @group = Group.find(params[:group][:requested_group]) if params[:group][:requested_group] @groups_user = GroupsUser.where(:group_id => @group.id, :user_id => current_user.id).first_or_create unless params[:group][:app_infos].blank? # merge non-empty app_infos new_app_infos = params[:group][:app_infos].reject {|key, value| value.blank? } current_user.merge_app_infos(new_app_infos) end # send mail to group admins Registrations.group_user_registration_email( @group, current_user, edit_groups_user_url(@groups_user) ).deliver redirect_to user_confirm_path end |
#show ⇒ Object
GET /groups_users/1 GET /groups_users/1.json
20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/groups_users_controller.rb', line 20 def show @groups = admin_groups(@groups) @groups_user = GroupsUser.where(:group_id => @groups).find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render :json => @groups_user } end end |
#show_group ⇒ Object
show and manage users for a group
137 138 139 140 |
# File 'app/controllers/groups_users_controller.rb', line 137 def show_group @group = @groups.find(params[:group]) @groups_users = GroupsUser.where(:group_id => @group).joins(:group, :user).order('groups.name,users.login') end |
#update ⇒ Object
PUT /groups_users/1 PUT /groups_users/1.json
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/groups_users_controller.rb', line 88 def update @groups = admin_groups(@groups) @groups_user = GroupsUser.where(:group_id => @groups).find(params[:id]) respond_to do |format| if @groups_user.update_attributes(params[:groups_user]) format.html { redirect_to group_path(@groups_user.group), :notice => 'Gruppenfreigabe wurde erfolgreich gespeichert.' } format.json { head :ok } else format.html { render :action => "edit" } format.json { render :json => @groups_user.errors, :status => :unprocessable_entity } end end end |