mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 14:40:27 +00:00
Merge remote-tracking branch 'hackedd/feature/server-side-domain-list' into development
This commit is contained in:
commit
f318c437c1
@ -304,16 +304,18 @@ class User(db.Model):
|
||||
db.session.rollback()
|
||||
return False
|
||||
|
||||
def get_domain_query(self):
|
||||
return db.session.query(User, DomainUser, Domain) \
|
||||
.filter(User.id == self.id) \
|
||||
.filter(User.id == DomainUser.user_id) \
|
||||
.filter(Domain.id == DomainUser.domain_id)
|
||||
|
||||
def get_domain(self):
|
||||
"""
|
||||
Get domains which user has permission to
|
||||
access
|
||||
"""
|
||||
user_domains = []
|
||||
query = db.session.query(User, DomainUser, Domain).filter(User.id==self.id).filter(User.id==DomainUser.user_id).filter(Domain.id==DomainUser.domain_id).all()
|
||||
for q in query:
|
||||
user_domains.append(q[2])
|
||||
return user_domains
|
||||
return [q[2] for q in self.get_domain_query()]
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
|
@ -144,53 +144,11 @@
|
||||
<th>Type</th>
|
||||
<th>Serial</th>
|
||||
<th>Master</th>
|
||||
<th>Action</th>
|
||||
<th {% if current_user.role.name !='Administrator' %}width="6%"{% else %}width="20%"{% endif %}>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for domain in domains %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ url_for('domain', domain_name=domain.name) }}"><strong>{{ domain.name }}</strong></a>
|
||||
</td>
|
||||
<td>
|
||||
{% if domain.dnssec %}
|
||||
<button type="button" class="btn btn-flat dnssec btn-success button_dnssec" id="{{ domain.name }}" style="width:100%;">
|
||||
<i class="fa fa-lock"></i> Enabled
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="button" class="btn btn-flat dnssec button_dnssec" id="{{ domain.name }}" style="width:100%;">
|
||||
<i class="fa fa-unlock-alt"></i> Disabled
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ domain.type }}
|
||||
</td>
|
||||
<td>
|
||||
{% if domain.serial == 0 %}{{ domain.notified_serial }}{% else %}{{domain.serial}}{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if domain.master == '[]'%}N/A {% else %}{{ domain.master|display_master_name }}{% endif %}
|
||||
</td>
|
||||
{% if current_user.role.name !='Administrator' %}
|
||||
<td width="6%">
|
||||
<button type="button" class="btn btn-flat btn-success" onclick="window.location.href='{{ url_for('domain', domain_name=domain.name) }}'">
|
||||
Manage <i class="fa fa-cog"></i>
|
||||
</button>
|
||||
</td>
|
||||
{% else %}
|
||||
<td width="20%">
|
||||
<button type="button" class="btn btn-flat btn-success" onclick="window.location.href='{{ url_for('domain', domain_name=domain.name) }}'">
|
||||
Manage <i class="fa fa-cog"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-flat btn-danger" onclick="window.location.href='{{ url_for('domain_management', domain_name=domain.name) }}'">
|
||||
Admin <i class="fa fa-cog"></i>
|
||||
</button>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<!-- Content loaded via AJAX. -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -214,13 +172,16 @@
|
||||
"ordering" : false,
|
||||
"info" : false,
|
||||
"autoWidth" : false
|
||||
});
|
||||
});
|
||||
// set up domain list
|
||||
$("#tbl_domain_list").DataTable({
|
||||
"paging" : true,
|
||||
"lengthChange" : true,
|
||||
"searching" : true,
|
||||
"ordering" : true,
|
||||
"processing" : true,
|
||||
"serverSide" : true,
|
||||
"ajax" : "{{ url_for('dashboard_domains') }}",
|
||||
"info" : false,
|
||||
"autoWidth" : false,
|
||||
{% if default_domain_table_size_setting in ['10','25','50','100'] %}
|
||||
|
46
app/templates/dashboard_domain.html
Normal file
46
app/templates/dashboard_domain.html
Normal file
@ -0,0 +1,46 @@
|
||||
{% macro name(domain) %}
|
||||
<a href="{{ url_for('domain', domain_name=domain.name) }}"><strong>{{ domain.name }}</strong></a>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro dnssec(domain) %}
|
||||
{% if domain.dnssec %}
|
||||
<button type="button" class="btn btn-flat dnssec btn-success button_dnssec" id="{{ domain.name }}" style="width:100%;">
|
||||
<i class="fa fa-lock"></i> Enabled
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="button" class="btn btn-flat dnssec button_dnssec" id="{{ domain.name }}" style="width:100%;">
|
||||
<i class="fa fa-unlock-alt"></i> Disabled
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro type(domain) %}
|
||||
{{ domain.type }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro serial(domain) %}
|
||||
{% if domain.serial == 0 %}{{ domain.notified_serial }}{% else %}{{domain.serial}}{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro master(domain) %}
|
||||
{% if domain.master == '[]'%}N/A{% else %}{{ domain.master|display_master_name }}{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro actions(domain) %}
|
||||
{% if current_user.role.name !='Administrator' %}
|
||||
<td width="6%">
|
||||
<button type="button" class="btn btn-flat btn-success" onclick="window.location.href='{{ url_for('domain', domain_name=domain.name) }}'">
|
||||
Manage <i class="fa fa-cog"></i>
|
||||
</button>
|
||||
</td>
|
||||
{% else %}
|
||||
<td width="20%">
|
||||
<button type="button" class="btn btn-flat btn-success" onclick="window.location.href='{{ url_for('domain', domain_name=domain.name) }}'">
|
||||
Manage <i class="fa fa-cog"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-flat btn-danger" onclick="window.location.href='{{ url_for('domain_management', domain_name=domain.name) }}'">
|
||||
Admin <i class="fa fa-cog"></i>
|
||||
</button>
|
||||
</td>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
71
app/views.py
71
app/views.py
@ -283,10 +283,6 @@ def logout():
|
||||
@login_required
|
||||
def dashboard():
|
||||
d = Domain().update()
|
||||
if current_user.role.name == 'Administrator':
|
||||
domains = Domain.query.all()
|
||||
else:
|
||||
domains = User(id=current_user.id).get_domain()
|
||||
|
||||
# stats for dashboard
|
||||
domain_count = Domain.query.count()
|
||||
@ -299,7 +295,72 @@ def dashboard():
|
||||
uptime = list([uptime for uptime in statistics if uptime['name'] == 'uptime'])[0]['value']
|
||||
else:
|
||||
uptime = 0
|
||||
return render_template('dashboard.html', domains=domains, domain_count=domain_count, users=users, history_number=history_number, uptime=uptime, histories=history)
|
||||
return render_template('dashboard.html', domain_count=domain_count, users=users, history_number=history_number, uptime=uptime, histories=history)
|
||||
|
||||
|
||||
@app.route('/dashboard-domains', methods=['GET'])
|
||||
@login_required
|
||||
def dashboard_domains():
|
||||
if current_user.role.name == 'Administrator':
|
||||
domains = Domain.query
|
||||
else:
|
||||
domains = User(id=current_user.id).get_domain_query()
|
||||
|
||||
template = app.jinja_env.get_template("dashboard_domain.html")
|
||||
render = template.make_module(vars={"current_user": current_user})
|
||||
|
||||
columns = [Domain.name, Domain.dnssec, Domain.type, Domain.serial, Domain.master]
|
||||
# History.created_on.desc()
|
||||
order_by = []
|
||||
for i in range(len(columns)):
|
||||
column_index = request.args.get("order[%d][column]" % i)
|
||||
sort_direction = request.args.get("order[%d][dir]" % i)
|
||||
if column_index is None:
|
||||
break
|
||||
if sort_direction != "asc" and sort_direction != "desc":
|
||||
sort_direction = "asc"
|
||||
|
||||
column = columns[int(column_index)]
|
||||
order_by.append(getattr(column, sort_direction)())
|
||||
|
||||
if order_by:
|
||||
domains = domains.order_by(*order_by)
|
||||
|
||||
total_count = domains.count()
|
||||
|
||||
search = request.args.get("search[value]")
|
||||
if search:
|
||||
start = "" if search.startswith("^") else "%"
|
||||
end = "" if search.endswith("$") else "%"
|
||||
domains = domains.filter(Domain.name.ilike(start + search.strip("^$") + end))
|
||||
|
||||
filtered_count = domains.count()
|
||||
|
||||
start = int(request.args.get("start", 0))
|
||||
length = min(int(request.args.get("length", 0)), 100)
|
||||
domains = domains[start:start + length]
|
||||
|
||||
if current_user.role.name != 'Administrator':
|
||||
domains = [d[2] for d in domains]
|
||||
|
||||
data = []
|
||||
for domain in domains:
|
||||
data.append([
|
||||
render.name(domain),
|
||||
render.dnssec(domain),
|
||||
render.type(domain),
|
||||
render.serial(domain),
|
||||
render.master(domain),
|
||||
render.actions(domain),
|
||||
])
|
||||
|
||||
response_data = {
|
||||
"draw": int(request.args.get("draw", 0)),
|
||||
"recordsTotal": total_count,
|
||||
"recordsFiltered": filtered_count,
|
||||
"data": data,
|
||||
}
|
||||
return jsonify(response_data)
|
||||
|
||||
|
||||
@app.route('/domain/<path:domain_name>', methods=['GET', 'POST'])
|
||||
|
Loading…
Reference in New Issue
Block a user