-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding permissions tab for webapps plugin
- Loading branch information
Showing
15 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#alias-delete-icon{ | ||
background: url("img/delete.png"); | ||
height: 19px; | ||
width: 19px; | ||
display: inline-block; | ||
text-indent: -9999px; | ||
} | ||
.settings-table{ | ||
margin-top: 30px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Amahi Home Server | ||
# Copyright (C) 2007-2013 Amahi | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License v3 | ||
# (29 June 2007), as published in the COPYING file. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# file COPYING for more details. | ||
# | ||
# You should have received a copy of the GNU General Public | ||
# License along with this program; if not, write to the Amahi | ||
# team at http://www.amahi.org/ under "Contact Us." | ||
|
||
require 'command' | ||
require 'platform' | ||
|
||
|
||
class WebappAccess < ActiveRecord::Base | ||
|
||
attr_accessible :webapp_id, :access_to | ||
belongs_to :webapps | ||
|
||
|
||
def getUsers | ||
user_ids = JSON.parse(self.access_to) | ||
@users_allowed = [] | ||
user_ids.each do |user_id| | ||
@users_allowed << User.find(user_id) | ||
end | ||
@users_allowed | ||
end | ||
|
||
def remove_all_users | ||
self.access_to = [].to_s | ||
self.save! | ||
end | ||
|
||
def addUser(user,password) | ||
users = JSON.parse(self.access_to) | ||
if(!users.include?(user.id)) | ||
users = users << user.id | ||
end | ||
self.access_to = users.to_s | ||
self.save! | ||
webapp = Webapp.find(self.webapp_id) | ||
path = webapp.path | ||
htpasswd_path = path+'/htpasswd' | ||
if(File.file?(htpasswd_path)) | ||
c = Command.new "htpasswd -bm #{htpasswd_path} #{user.login} #{password}" | ||
else | ||
c = Command.new "htpasswd -cbm #{htpasswd_path} #{user.login} #{password}" | ||
end | ||
c.execute | ||
Platform.reload(:apache) | ||
end | ||
|
||
def removeUser(user) | ||
users = JSON.parse(self.access_to) | ||
if(users.include?(user.id)) | ||
users.delete(user.id) | ||
end | ||
self.access_to = users.to_s | ||
self.save! | ||
webapp = Webapp.find(self.webapp_id) | ||
path = webapp.path | ||
htpasswd_path = path+'/htpasswd' | ||
if(File.file?(htpasswd_path)) | ||
c = Command.new "htpasswd -D #{htpasswd_path} #{user.login}" | ||
c.execute | ||
end | ||
Platform.reload(:apache) | ||
|
||
end | ||
|
||
def self.find_or_create(webapp_id) | ||
webapp_access = WebappAccess.where(:webapp_id=>webapp_id).first | ||
if(webapp_access == nil) | ||
webapp_access = WebappAccess.create(:webapp_id=>webapp_id,:access_to=>[].to_s) | ||
end | ||
webapp_access | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- @webapp = webapp | ||
- return if @webapp.nil? | ||
- uid = @webapp.id.to_s | ||
- @users_allowed = WebappAccess.find_or_create(@webapp.id).getUsers | ||
div.webapp[id="whole_webapp_#{uid}"] | ||
table.settings.stretchtoggle id="webapp_row_#{uid}" | ||
tr | ||
td.settings-col1.webapps-col1 | ||
= link_to(@webapp.name, '') | ||
td.settings-col2.webapps-col2 id="webapp_url_#{uid}" | ||
a href=("http://#{webapp.name}") target="_" | ||
| http://#{@webapp.name} | ||
.settings-stretcher id="webapp_info_#{uid}" style="display:none;" | ||
.webapp-manage | ||
fieldset | ||
legend | ||
| #{t 'edit_web_app_permission_for'} | ||
b= h(@webapp.name) | ||
| | ||
.settings-fields | ||
table | ||
-for item in @users | ||
-@user = item | ||
tr[id="permission_webapp#{@webapp.id}_user#{@user.id}"] | ||
= render :partial=>'user_permissions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-checked = @users_allowed.include?@user | ||
|
||
td = @user.name | ||
td | ||
span | ||
- if checked | ||
= link_to("[x]",webapps_engine.remove_permission_webapp_path(:id => @user.id,:webapp_id=>@webapp.id), {:remote=>true, :method=>:delete, :class=>:edit_form, :id=>'alias-delete-icon'}) | ||
- else | ||
a.click_change Add Permission | ||
form.edit_form.form_hidden action=webapps_engine.add_permission_webapp_path(:id => @user.id,:webapp_id=>@webapp.id) data-remote="true" method="post" style=("display: none;") | ||
input id="text_webapp_#{@user.id}" name="password" type="password" | ||
button.btn.btn-create.margin-for-message type="submit" | ||
span = t('add') | ||
a.cancel_link Cancel | ||
span.spinner.theme-image style=("display: none") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
self.formats = [:html] | ||
json.status :ok | ||
json.type :permission | ||
json.webappid @webapp.id | ||
json.userid @user.id | ||
json.content render(:partial => 'user_permissions') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#webapps-table | ||
.settings-table | ||
- if @webapps.size > 0 | ||
table.settings | ||
thead | ||
tr | ||
th.settings-col1.webapps-col1 scope="col" = t 'name' | ||
th.settings-col2.webapps-col2 scope="col" = t 'url' | ||
tbody | ||
= render :partial => 'permission_webapp', :collection => @webapps, :as=> :webapp | ||
- else | ||
div align="center" | ||
div align="left" | ||
h2= t 'there_are_no_webapps' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
self.formats = [:html] | ||
json.status @status | ||
json.type :permission | ||
json.webappid @webapp.id | ||
json.userid @user.id | ||
json.content render(:partial => 'user_permissions') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateWebappAccesses < ActiveRecord::Migration | ||
def change | ||
create_table "webapp_accesses" do |t| | ||
t.integer "webapp_id" | ||
t.string "access_to" | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters