summaryrefslogtreecommitdiff
path: root/app/controllers/user_group_memberships_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/user_group_memberships_controller.rb')
-rw-r--r--app/controllers/user_group_memberships_controller.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/app/controllers/user_group_memberships_controller.rb b/app/controllers/user_group_memberships_controller.rb
new file mode 100644
index 0000000..1cbbd48
--- /dev/null
+++ b/app/controllers/user_group_memberships_controller.rb
@@ -0,0 +1,48 @@
+class UserGroupMembershipsController < ApplicationController
+ load_and_authorize_resource :user_group
+ load_and_authorize_resource :user_group_membership, :through => [:user_group]
+
+ before_filter :spread_breadcrumbs
+
+ def index
+ @potential_users_count = @user_group.tenant.users.count - @user_group.users.count
+ end
+
+ def show
+ end
+
+ def new
+ @user_group_membership = @user_group.user_group_memberships.build
+ @potential_users = (@user_group.tenant.users.order(:last_name) - @user_group.users)
+ if @potential_users.count == 0
+ redirect_to user_group_user_group_memberships_path(@user_group), :alert => t('user_group_memberships.controller.no_more_user_to_add')
+ end
+ end
+
+ def create
+ @user_group_membership = @user_group.user_group_memberships.build(params[:user_group_membership])
+ if @user_group_membership.save
+ redirect_to user_group_user_group_membership_path(@user_group, @user_group_membership), :notice => t('user_group_memberships.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def destroy
+ @user_group_membership.destroy
+ redirect_to user_group_user_group_memberships_path(@user_group), :notice => t('user_group_memberships.controller.successfuly_destroyed')
+ end
+
+ private
+
+ def spread_breadcrumbs
+ add_breadcrumb t("user_groups.index.page_title"), tenant_user_groups_path(@user_group.tenant)
+ add_breadcrumb @user_group, tenant_user_group_path(@user_group.tenant, @user_group)
+ add_breadcrumb t("user_group_memberships.index.page_title"), user_group_user_group_memberships_path(@user_group)
+
+ if @user_group_membership && !@user_group_membership.new_record?
+ add_breadcrumb @user_group_membership, user_group_user_group_membership_path(@user_group, @user_group_membership)
+ end
+ end
+
+end